-
- author "me"
- fileName "Dom"
- tags ""
- description ""
- Dom is ______
- Document Object Model
-
Dom Methods
getElementById(" ")
getElementsByTagName(" CAP ")
-
-
Step 1
Example
var myPtag = document.getElementById("P1");
-
Step 2
You can do anything u want after u have a handle
-
Examples of step 2,
Changing text
myPtag.innerHTML = "new text"
-
Examples of step 2
Assigning CSS class using className property
myPtag.classname = "newCssClass";
-
Examples of step 2
Changing online style (ie text color) using the style property
myPtag.style.color = "#900";
-
Using method getElementsByTagName
Is more specific than getElementById
-
getElementById is _____ than getElementsByTagName, so usually ______
- Broader
- Use get ElementById first
-
Example of using the getElementsByTagName method
var container, myLItags;
- container = document.getElementById("exams");
- // remember use caps when identifying tag names
- myLItags = container.getElementsByTagName("LI");
-
Once, you get from getElementsByTagName, it comes in as
Array
-
You can use array notification to specify
myLItags[1].style.backgroundColor = "#fff";
You can also use loops to access elements
-
Loop to access all the elements
- for (var n = 0, len = myLItags.length, n<0, n++) {
- if (myLITags [n].innerHTML === "100") {
- myLITags[ ].style.font = "120%")
- }
- }
|
|