jQuery: The Write Less, Do More JavaScript Library

How to get references to added elements

View: New views
3 Messages — Rating Filter:   Alert me  

How to get references to added elements

by kheraud@gmail.com :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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.

Re: How to get references to added elements

by Richard D. Worth-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Use insertAfter() instead. See


- Richard

On Thu, Nov 5, 2009 at 5:50 PM, kheraud <kheraud@...> 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.


Re: How to get references to added elements

by kheraud@gmail.com :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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...@...> wrote:

> 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...@...> 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.