Why ID is still working for multiple elements as well?


#1



Replace this line with your code. 
 whats the differnce between id and class then if ID can be used for multiple elements?
<!DOCTYPE html>
<html>
	<head>
		<link type="text/css" rel="stylesheet" href="stylesheet.css"/>
		<title>Result</title>
	</head>
	<body>
		<!--Add your HTML elements with the ID "serious" below!-->
		<p id="serious">yoyi</p>
		<h5 id="serious"> i am rare</h5>
	</body>
</html>




CSS code

/*Define your CSS id #serious below!*/
#serious{
    font-family:Courier;
    color:#cc0000;
}


#2

unfortunately browsers today allow you to use the same id name multiply times. Bad practice. If an element has both an id and class, the id property's get applied (if both id and class for example have a color property, the color of id gets applied)

Also, when using jquery only one elements work with id, where multiply work with classes, so it is still important


#3

So you are saying that because of browsers , id is can be applied for multiple elements but usually it doesnt work that way right, in jQuery id is applicable only once right?


#4

yes, exactly what i am saying. I problems with some jquery code because i was so stupid to use a id instead of an element while i had multiply with the same name.

So, use id's only once per page, for important things, and classes for the rest.


#5

what about the first sentence that I wrote ?about the browsers thing? thanks for you reply means a lot!


#6

well, long time ago browser didn't support using the same id name multiply times, which causes problem loading the webpage. Today this changed, but because of the stronger css for id's and so on, i would still follow w3c recommendations to use id's only once.


#7

thank you for your reply and time!