+ 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.

30th Dec 2018, 3:18 AM
Alex K
Alex K - avatar
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.
30th Dec 2018, 4:01 AM
Calviղ
Calviղ - avatar
+ 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 }
30th Dec 2018, 3:28 AM
Calviղ
Calviղ - avatar
+ 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.
30th Dec 2018, 3:55 AM
Alex K
Alex K - avatar
+ 1
Thank You Calviղ
30th Dec 2018, 4:04 AM
Alex K
Alex K - avatar
+ 1
Because they are come under div command
18th Jan 2019, 8:43 AM
Naresh Chahar
Naresh Chahar - avatar
0
I think its important or must to choice either
31st Dec 2018, 3:59 PM
Eng Mohamud Mohamed Abdullahi
Eng Mohamud Mohamed Abdullahi - avatar
0
U can use : before div then put the class and id Example: Before div[id="id1"] Or Before .class2 div [id="id4"] .................
13th Jan 2019, 9:23 AM
hanen mdaghi
hanen mdaghi - avatar