HighDots Forums  

How to get references to added elements

jQuery jQuery is a fast, concise, JavaScript Library that simplifies how you traverse HTML documents, handle events, perform animations, and add Ajax interactions to your web pages. jQuery is designed to change the way that you write JavaScript.


Discuss How to get references to added elements in the jQuery forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
kheraud
 
Posts: n/a

Default How to get references to added elements - 11-05-2009 , 05:50 PM






Hello,

Thank you to help me to discover jQuery. I have a very easy question
but i walk around the solutions for days.

//I search for sub-elements with class "test" of paragraphs :
var elementSearched = $("p .test");

//Then I add a new nodes to these elements :
var returnedVar = elementSearched.after("<div class="subtest">Hello</
div>");

My aim is to add handlers already present on other nodes to these new
nodes. But "returnedVar" is not the new nodes added but the old one
targetted. Then I have to search for the new nodes added to apply the
handler. It is hard and if I apply the handler to a node already
handled, my handler is done twice for this node.

How can I have references to the nodes added with .after method ?

Thank you for your help.

Reply With Quote
  #2  
Old   
Richard D. Worth
 
Posts: n/a

Default Re: [jQuery] How to get references to added elements - 11-06-2009 , 01:29 AM






Use insertAfter() instead. See

http://docs.jquery.com/Manipulation/insertAfter

<http://docs.jquery.com/Manipulation/insertAfter>- Richard

On Thu, Nov 5, 2009 at 5:50 PM, kheraud <kheraud (AT) gmail (DOT) com> wrote:

Quote:
Hello,

Thank you to help me to discover jQuery. I have a very easy question
but i walk around the solutions for days.

//I search for sub-elements with class "test" of paragraphs :
var elementSearched = $("p .test");

//Then I add a new nodes to these elements :
var returnedVar = elementSearched.after("<div class="subtest">Hello</
div>");

My aim is to add handlers already present on other nodes to these new
nodes. But "returnedVar" is not the new nodes added but the old one
targetted. Then I have to search for the new nodes added to apply the
handler. It is hard and if I apply the handler to a node already
handled, my handler is done twice for this node.

How can I have references to the nodes added with .after method ?

Thank you for your help.

Reply With Quote
  #3  
Old   
kheraud
 
Posts: n/a

Default Re: How to get references to added elements - 11-06-2009 , 07:02 PM



Thank you very much for your help.

But in fact, that does not work. XXX.insertAfter(YYY) needs that XXX
is already a node of the document. And in fact, I want to insert a new
node ("<ZZZ VVV="RRR">...</ZZZ>).

So, the problem is still there...

Do you have an idea to solve it ?

Thanks again for your help

On Nov 6, 7:29*am, "Richard D. Worth" <rdwo... (AT) gmail (DOT) com> wrote:
Quote:
Use insertAfter() instead. See

http://docs.jquery.com/Manipulation/insertAfter

http://docs.jquery.com/Manipulation/insertAfter>- Richard

On Thu, Nov 5, 2009 at 5:50 PM, kheraud <kher... (AT) gmail (DOT) com> wrote:
Hello,

Thank you to help me to discover jQuery. I have a very easy question
but i walk around the solutions for days.

//I search for sub-elements with class "test" of paragraphs :
var elementSearched = $("p .test");

//Then I add a new nodes to these elements :
var returnedVar = elementSearched.after("<div class="subtest">Hello</
div>");

My aim is to add handlers already present on other nodes to these new
nodes. But "returnedVar" is not the new nodes added but the old one
targetted. Then I have to search for the new nodes added to apply the
handler. It is hard and if I apply the handler to a node already
handled, my handler is done twice for this node.

How can I have references to the nodes added with .after method ?

Thank you for your help.

Reply With Quote
Reply




Thread Tools
Display Modes

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

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



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.