+ 3
Why we can only use or select the class or id which are inside <div> html tag?
I cannot select the class outside the <div> tag to style. Any answer would be appreciated.
7 Respuestas
+ 2
Khun Tee Bwar for css, you're right, the selector can only select his own, sibling or child elements, not parent element.
+ 3
You could use parentElement.
parentElement is the parent element of the current node. It return a DOM Element object or return null if no parent element exists.
Eg
if (divNode.parentElement) {
divNode.parentElement.style.color = "red"; // set text color of parent node
}
+ 1
thank you for your answer Calviղ , I need to learn more to understand and ultilize your example.
i only know html at the moment.
+ 1
Thank You Calviղ
+ 1
Because they are come under div command
0
I think its important or must to choice either
0
U can use :
before div then put the class and id
Example:
Before div[id="id1"]
Or
Before .class2 div [id="id4"]
.................