var IMGs = document.queryselectorall ("article img");
Gets all the IMG elements of the immediate or indirect descendants of the article element,
<article> <div> </div></ Article>
Gets a 2 img element.
Another method, Queryselector (), returns only the first result found.
Other syntax differences for acquiring elements are:
Get article Direct child element: var IMGs = Document.queryselectorall ("article> img");
Gets all the elements immediately following an element: var IMGs = Document.queryselectorall ("img + P");
Gets an element of an empty property: var IMGs = Document.queryselectorall ("img[alt=");
Gets an element for which the property is not empty: var IMGs = Document.queryselectorall ("Img:not ([alt=])");
/*queryselectorall () Gets a collection of elements that are not "dynamic", and if the update is published after the collection is acquired, the updates made by the page are not reflected in the collection, and the getElementById () usually used is more efficient */
CSS style settings (three types):
Modified by the style property of the element: Elem.style.backgroundColor = "Red";
/* Style name "Hump" notation, second word capital */
To modify one or more properties of a single element:
Elem.setattribute ("Style", "background-color:red; Color:white; BORDER:1PX solid black ");
predefined styles, setting the class property of an element:
1 . stipe{2 background-color:red; 3 Color:white; 4 border:1px solid black; 5 }6.... 7 Elem.setattribute ("Class", "stripe");
For getting an element property value using GetAttribute (),
To access the specific style settings of an element at a particular point in time, it is more complicated and not quite clear, here first an example, for later reference:
var elem = document.getElementById ("test"); var bkcolor = Elem.currentstyle? elem.currentstyle["BackgroundColor"]: window.getComputedStyle (Elem). GetPropertyValue ("Background-color"); Console.log (Bkcolor);
Can work across browsers, and later contact to re-study it!
JS Learning Advanced-element acquisition and style setting