javascript - Select next element of a given class -


I want to hide and show some form in my page.

There is a link for each form,

My code looks like this:

  $$ ('I') Click on this link Please, .flagLink '). Each (function (s) {$ (s) .observe ('click', function (event) {// here to hide and show the closest form}};});  
< P> I tried to:

  $$ ('. FlagLink'). (Function (s) {$ (s). 'Click', function (event) { $ (S) .next ('form') Toggle ();});});  

This works, but I'd like to be more precise:

  $$ ('. FlagLink'). Each (function (s) {$ (s) .bosch ('click', function (event) {$ (s) .next ('. FlagForm') toggle ();});});  

But the .flagForm selector does not work.

My code looks like this: Flag

First of all I hide all the forms in the page:

$$ ('. FlagForm') . Each (function (s) {$ (s) .hide ();});

Then I add an onclick event to them:

  $$ ('. FlagLink'). Each (function (s) {$ (s) .bosch ('click', function (event) {$ (s) .next ('.flagfarm'). Toggle ();});});  

But with the .flagForm selector, it does not work

To avoid dangerous DOM traversal, I recommend using element ID to bind a form on its link, such as:

   

You can then copy the ID of your A element from a regexp / link _ (. *) / to get the ID You can mail your form:

  $$ ('. FlagLink'). Call ('Inspect', 'Click', Function (Event) {if (event.element). Id.match (/ link _ (. *) /)) $ (RegExp. $ 1) Toggle ( );});  

If you can not use this solution, then you should be more specific about what it means to "closest". If there is always a general ancestor in the link and form, you can use the CSS selector wherever you are looking for the form. Ask the link and the form always has a normal ancestor, which is a great-parent of the link, you can do this:

  $$ ('. FlagLink'). 'Click', function (event) {var form = event.element (). Up (2) .select ('form'). first (); If (form) form.toggle ();});  

Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -