SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Thread: insertAfter in jquery

  1. #1
    SitePoint Member
    Join Date
    Dec 2011
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    insertAfter in jquery

    i use insertAfter to insert a div tag in to an element.
    HTML Code:
    $("<div class='redBox'>Iron man</div>").insertAfter('#footer');
    <div class='redBox'>Iron man</div> displayed in web browse. but when view source (ctr+u) not display

  2. #2
    SitePoint Mentor bronze trophy
    chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,041
    Mentioned
    9 Post(s)
    Tagged
    1 Thread(s)
    That is exactly how browsers are designed to work, when you manipulate the DOM any new element introduced into the source won't be shown as it can only see what was loaded when you initially opened the page. To view new elements you will need to use Firebug for Firefox or the Chrome developer tools which are built into Google Chrome.
    Blog/Portfolio | Evolution Xtreme | DFG Design | DFG Hosting | CSS-Tricks | Stack Overflow | Paul Irish
    Having lame problems with your code? Let us help by using a jsFiddle

  3. #3
    SitePoint Member
    Join Date
    Dec 2011
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    but $("<div class='redBox'>Iron man</div>").insertAfter('#footer'); called in $(document).ready(function() { }

  4. #4
    SitePoint Mentor bronze trophy
    chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,041
    Mentioned
    9 Post(s)
    Tagged
    1 Thread(s)
    My above comments are the answer to your question, regardless of how you insert your new HTML into the DOM is will never show up in the view source window as it is stored in the browser memory on load and never changed regardless of what happens in the DOM.
    Blog/Portfolio | Evolution Xtreme | DFG Design | DFG Hosting | CSS-Tricks | Stack Overflow | Paul Irish
    Having lame problems with your code? Let us help by using a jsFiddle

  5. #5
    SitePoint Member
    Join Date
    Dec 2011
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if use live method?

  6. #6
    SitePoint Mentor bronze trophy
    chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,041
    Mentioned
    9 Post(s)
    Tagged
    1 Thread(s)
    Again nothing you do will result in the new HTML showing up in the view source window, its 100% impossible for it to show up there.
    Blog/Portfolio | Evolution Xtreme | DFG Design | DFG Hosting | CSS-Tricks | Stack Overflow | Paul Irish
    Having lame problems with your code? Let us help by using a jsFiddle

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •