Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
182
rated 0 times [  188] [ 6]  / answers: 1 / hits: 49002  / 15 Years ago, sun, november 29, 2009, 12:00:00
$(document).ready(function() {
$('a.menuitem').click(function() {
var arr = 0;
var link = $( this ), url = link.attr( href );
var newDiv = $( document.createElement( 'div' ) )
$( #content_pane ).append( newDiv );
newDiv.load( url );
return false;
});
});


As you can see I am creating a div and adding some content to it, how would I give each div that is created a unique id, something like section1, section2, section3, etc?


More From » jquery

 Answers
11

Just use a counter:



var section = 1;
$(function() {
$(a.menuitem).click(function() {
...
$(<div></div>).attr(id, section + section++).appendTo(#content_pane);
...
return false;
});
});


Also, I'd suggest creating the element as per above.


[#98199] Wednesday, November 25, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
feliciarainak

Total Points: 104
Total Questions: 91
Total Answers: 83

Location: Greenland
Member since Thu, Oct 27, 2022
2 Years ago
;