Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    86
    Thanks
    20
    Thanked 0 Times in 0 Posts

    Retrieveing & inserting contents

    @ http://jsfiddle.net/defencedog/cu5VJ/

    I am having problem in understanding the operation of js with regards to this line
    Code:
     $('.' + x[i].id).text(x[i].innerHTML);
    or

    Code:
      $('.' + x[i].id).html(x[i].innerHTML);
    I want to understand why I ain't able to produce desired results while using this instead

    Code:
    $('.' + x[i].id).innerHTML(x[i].innerHTML);

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,398
    Thanks
    12
    Thanked 570 Times in 563 Posts
    Because .innerHTML simply isn't a method of a jQuery object whereas .html() is ... .innerHTML is a property of a DOM element and not a method

    Code:
    // get a DOM element
    var DOMel = document.getElementById('myid');
    DOMel.innerHTML = "<b>whatever</b>";
    
    // get a jQuery object and set its html
    $('#myid').html("<b>whatever</b>");


  •  

    Posting Permissions

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