Reputation: 52
i want to append a tag to with different ids, for eg.
<div id="1"></div>
<div id="2"></div>
<div id="3"></div>
<div id="4"></div>
if i use $('div').append('<span>Hello World</span>);
then it attached the <span>
tag with every <div>
, but i want to attach it to only 1 div based on it id. for example some time to 4 some times to 3 etc.
Upvotes: 1
Views: 2845
Reputation: 3226
Just use the ID selector:
$('#1').append('<span>Hello World</span>');
Edit: IF you don't use HTML5:
You can't use numbers in IDs or classes when they don't follow a char. So you need use id="div1" instead:
$('#div1').append('<span>Hello World</span>');
Upvotes: 3
Reputation: 2821
Use the wonderful id selector offered by JQuery:)
$("#1").append('<span>Hello World</span>');
Upvotes: 5