Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

$(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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
201 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...