Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-19-2011, 06:38 AM   PM User | #1
narek
New Coder

 
Join Date: Feb 2010
Location: Armenia
Posts: 41
Thanks: 17
Thanked 0 Times in 0 Posts
narek has a little shameless behaviour in the past
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???
narek is offline   Reply With Quote
Old 09-19-2011, 08:19 AM   PM User | #2
thesam101
New Coder

 
Join Date: Apr 2010
Location: Norfolk, England
Posts: 63
Thanks: 1
Thanked 14 Times in 14 Posts
thesam101 is an unknown quantity at this point
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.//
thesam101 is offline   Reply With Quote
Old 09-19-2011, 01:08 PM   PM User | #3
VIPStephan
The fat guy next door


 
VIPStephan's Avatar
 
Join Date: Jan 2006
Location: Halle (Saale), Germany
Posts: 7,587
Thanks: 5
Thanked 864 Times in 841 Posts
VIPStephan is a jewel in the roughVIPStephan is a jewel in the roughVIPStephan is a jewel in the rough
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.
__________________
Don’t click this link!
VIPStephan is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:10 AM.


Advertisement
Log in to turn off these ads.