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 3 of 3
  1. #1
    New Coder
    Join Date
    Feb 2010
    Location
    Armenia
    Posts
    41
    Thanks
    17
    Thanked 0 Times in 0 Posts

    Disappearing paragraphs after jQuery excecution

    Hello . Please help me .Here is the code
    Code:
    <script type="text/javascript" src="jquery.js" ></script>
    <p class="book">11111</p>
    <p class="book">2222</p>
    <p class="book">3333</p>
    <p class="book">4444</p>
    <p class="book">5555</p>
    
    
    
    
    <script type="text/javascript">
    $(function(){
    document.write($("p").length);
    
    });
    
    </script>



    and it outputs only 5 and none of the paragraphs...WHY???

  • #2
    New Coder
    Join Date
    Apr 2010
    Location
    Norfolk, England
    Posts
    63
    Thanks
    1
    Thanked 14 Times in 14 Posts
    Hi narek

    document.write is ovewriting the paragraphs.

    add the value in to the page, a different way.

    Use innerHTML or set the value of a texbox.
    //Improvement in coding is iterative, each 'failure' is just the next step on your learning curve, some knowledge and logic can get you a long way.//

  • #3
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,662
    Thanks
    6
    Thanked 1,006 Times in 979 Posts
    Yeah, don’t use document.write, that’s very outdated and bad practice. With jQuery it’s soooo easy to append content, why are you using document.write anyway? Just write:
    Code:
    $('body').append($('<div>', {text: $("p").length}));
    … or something like this.


  •  

    Posting Permissions

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