Click operation mode --- --- nodes Case
Case 1: Click the button, set the node p discoloration way to do ---
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>title</title> <style> div { width: 200px; height: 200px; border: 1px solid hotpink; } </style> </head> <body> <the INPUT of the type = "the Button" value = "color" the above mentioned id = "btn" /> < div the above mentioned id = "dv" > < the p- > hoe Wo day when afternoon </ the p- > < the p- > sweat Wo soil </ the p- > < span > Surprisingly chopping block </ span > < br /> < span > A Journey </ span > < br /> < A the href = "#"> Poetry </ A> </ Div > < Script the src = "common.js" > </ Script > < Script > My $ ( " BTN " ) .onclick = function () { // first obtain div var dvObj = My $ ( " DV " ); // Get all the child nodes inside var nodes = dvObj.childNodes; // loop through all child nodes for ( var I = 0 ; I <nodes.length; I ++ ) { // determine whether this child node is not p tag, nodetype is 1 and nodename is uppercase P IF (Nodes [I] .nodeType == 1 && Nodes [I] .nodeName == " P " ) { Nodes [I] .style.backgroundColor = " Pink " ; } } }; </ Script > </ body > </ HTML >