In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-13 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
This article introduces the relevant knowledge of "how to realize Dom programming with Javascript". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Javascript Dom programming
One: Document Object Model
In the DOM model, each element (element), attribute (attribute), and text (text) can be regarded as an object. Javascript can access these objects independently, and these objects can be found and changed in some ways.
DOM states that the label of each HTML is an element node, the text contained in the element is a text node, and each HTML attribute is an attribute node.
Two: access the node of DOM
A: get elements through ID
Vartarget=document.getElementById ("berenger")
B: get elements through TagName
VarlistItems=document.getElementsByTagName ("li")
ListItems is an array-like object, and you can use listItems.Length to get the length of the object.
C: get elements through ClassName
In most cases in Javascript Dom programming, it is easier to use className to get elements than tagname, but dom does not provide a corresponding function, so we will create a method.
Can be broken down into the following three steps:
1: search for all elements in the document.
2: for each element, compare the class you belong to with the class you are looking for.
3: if the same, add it to the list.
The js code is as follows:
VarCore= {}; Core.getElementsByClass=function (theClass) {varelementArray= []; / IE does not support getElementsByTagName ("*"), use document.All. If (document.all) {elementArray=document.all;} else {elementArray=document.getElementsByTagName ("*");} varmatchedArray= []; varpattern=newRegExp ("(^ |)" + theClass+ "(| $)"); for (vari=0;i
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.