html() to more then one element - the same ID
#1
Hi

i have little problem
this is only exemple code
<html>

<head>
<script>
var mydiv = $("#mydiv_1");
mydiv.html("Test");
</script>
</head>
<body>
<h1>My Web Page</h1>
<div id="mydiv_1">This is a div element.</div>
<div id="mydiv_1">This is a div element.</div>
<div id="mydiv_2">This is a div element.</div>
<div id="mydiv_1">This is a div element.</div>
<div id="mydiv_2">This is a div element.</div>
</body>
</html>
this code change only first div
what I need to do?
My Plugins

PM only paid support
Reply
#2
Proper HTML is that each id attribute must be unique on the page. What you can do with jQuery is use a class selector instead since class names can be used repeatedly in the same web page.
Reply
#3
Set a class instead id, as @dragonexpert says id is an element on doctype and must be unique.

If you use a class then you got it.

var mydiv1 = $(".div1");

And

<div class="div1></div>

Finally add atributes and events and its done !!!

If you wanna use individual args use this value. Or use ids on divs.
The only infinite thing is the universe and human stupidity, but the universe is not for sure

Plugins 1.6.x

Plugins 1.8.x

Reply
#4
it solve my problem
thanks
My Plugins

PM only paid support
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)