Why is ID a global attribute but cannot apply to some elements | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 15

Why is ID a global attribute but cannot apply to some elements

12th Mar 2019, 7:19 PM
Hector Domingo{ }
Hector Domingo{ } - avatar
12 Answers
+ 6
Ok
12th Mar 2019, 8:23 PM
Hector Domingo{ }
Hector Domingo{ } - avatar
+ 6
JavaScript uses document.getElementsById to find the ID
12th Mar 2019, 8:39 PM
Hector Domingo{ }
Hector Domingo{ } - avatar
+ 6
I still don't understand Maybe it's because I don't have any knowledge about JavaScript
12th Mar 2019, 8:39 PM
Hector Domingo{ }
Hector Domingo{ } - avatar
+ 6
Thanks
13th Mar 2019, 4:42 AM
Hector Domingo{ }
Hector Domingo{ } - avatar
+ 6
Yes
13th Mar 2019, 5:19 PM
Hector Domingo{ }
Hector Domingo{ } - avatar
+ 5
//Its called Global attribute because it can be apply to all html elements
12th Mar 2019, 7:24 PM
Sudarshan Rai
Sudarshan Rai - avatar
+ 5
OK
12th Mar 2019, 7:34 PM
Hector Domingo{ }
Hector Domingo{ } - avatar
+ 4
But in one of the questions in challenging I saw a question which stated whether I'd can be applied to <p>.
12th Mar 2019, 7:26 PM
Hector Domingo{ }
Hector Domingo{ } - avatar
+ 4
#Id
12th Mar 2019, 7:27 PM
Hector Domingo{ }
Hector Domingo{ } - avatar
+ 2
Just to clarify confusion: You can use ID on any element you want. But you can only use it ONCE, if you use it more than once, the styling/JavaScript will only focus on the first/last ID in your HTML code. A special task for you: Google wether Styling and JavaScript uses your first ID or your last ID in your HTML document.
12th Mar 2019, 8:14 PM
Limitless
Limitless - avatar
+ 2
You're close enough :) So in the end, you should only apply a specific ID Attribute Value to one Element. Example <p id="Para1"> and <p id="Para2"> Hope this helped you a bit, enjoy!
13th Mar 2019, 4:34 AM
Limitless
Limitless - avatar
+ 1
Hector Domingo yup it can be apply on <p> tag
12th Mar 2019, 7:28 PM
Sudarshan Rai
Sudarshan Rai - avatar