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 10-08-2012, 02:46 AM   PM User | #1
johnsmith153
New Coder

 
Join Date: Mar 2012
Posts: 81
Thanks: 7
Thanked 0 Times in 0 Posts
johnsmith153 is infamous around these parts
Simple jQuery code

Why does this simple jQuery not work?

http://page-test.co.uk/jq.html

It should result in this:

<div class="main">
</div>
<div>1</div>
<div>2</div>
<div>3</div>
johnsmith153 is offline   Reply With Quote
Old 10-08-2012, 03:39 AM   PM User | #2
DanInMa
Senior Coder

 
DanInMa's Avatar
 
Join Date: Nov 2010
Location: Salem,Ma
Posts: 1,335
Thanks: 13
Thanked 207 Times in 207 Posts
DanInMa is on a distinguished road
Code:
var stored_html = "";

$(".main > div").each(function() {

	$(this).insertAfter(stored_html);

});

$(stored_html).insertAfter($(this).parent())
what do you intend for it to do exactly? the last line does nothing because you havent assigned it to an element, so using $(this).parent() does nothing, as it has no parent to reference.

the first part, well all you are doing is inserting, literally, nothing, not event a blank space.
__________________
- Firebug is a web developers best friend! - Learn it, Love it, use it!
- Validate your code! - JQ/JS troubleshooting
- Using jQuery with Other Libraries - Jslint for Jquery/other JS library users
DanInMa is offline   Reply With Quote
Old 10-08-2012, 03:44 AM   PM User | #3
johnsmith153
New Coder

 
Join Date: Mar 2012
Posts: 81
Thanks: 7
Thanked 0 Times in 0 Posts
johnsmith153 is infamous around these parts
I want to convert the HTML in the example to:

<div class="main">
</div>
<div>1</div>
<div>2</div>
<div>3</div>

... using this:
Code:
$(".main > div").each(function() {
...to pass through each div.

It's a small part of a larger script. I just pulled this out so as not to complicate things.
johnsmith153 is offline   Reply With Quote
Old 10-08-2012, 03:53 AM   PM User | #4
xelawho
Senior Coder

 
xelawho's Avatar
 
Join Date: Nov 2010
Posts: 2,461
Thanks: 52
Thanked 457 Times in 455 Posts
xelawho will become famous soon enoughxelawho will become famous soon enough
how is this question different from this one?
xelawho 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 05:43 AM.


Advertisement
Log in to turn off these ads.