jQuery - prepend and after method [Resolved]

Posted by Akiii under jQuery on 5/30/2011 | Points: 10 | Views : 4081 | Status : [Member] | Replies : 4
Hi,

Can anyone tell me what is the difference between jQuery prepend() and after() method...

$("p").append(" Akiii"); 

and

$("p").after(" Akiii123");


Thanks and Regards
Akiii




Responses

Posted by: Nithadeepak on: 5/31/2011 [Member] Bronze | Points: 50

Up
0
Down

Resolved
Hi akiii,

In after method another element is inserted after a specified element (not only a line break).
That means we can insert a button after a paragraph etc. (here 2 different elements ).


But in append(), a specified content is appended at the end of the element (inside the element). That is the same element is appended.

In the examples given in w3schools...


when we use after() One <p> element is inserted after a specified <p> element. That means there are two <p> elements in th page.

But when we use append() some contents are appended to the same <p> elements. So there is only one <p> element in the page.

If you got the point,mark it as resolved...

Thanks,


Nitha Deepak

Akiii, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Nithadeepak on: 5/30/2011 [Member] Bronze | Points: 25

Up
0
Down
Hi,

The append() method inserts specified content at the end of (but still inside) the selected elements.

The after() method inserts specified content after the selected elements. Ie, inserts another element after a specified element.


Refer these.....

http://www.w3schools.com/jquery/html_after.asp

http://www.w3schools.com/jquery/html_append.asp

Thanks,

Nitha Deepak

Akiii, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Akiii on: 5/31/2011 [Member] Bronze | Points: 25

Up
0
Down
hi..nitha..

thanks for your reply....
the after() is giving a line break and then writing the text while append() is writing the text next to it.....!

Regards
Akiii

Akiii, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Akiii on: 5/31/2011 [Member] Bronze | Points: 25

Up
0
Down
hi nitha....

Thank you very much for the explanation.....
much appreciated....

Thanks and Regards
Akiii

Akiii, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response