7

I am new in Prototype js. I have an element like this,

<li id="toolbar-save" class="button">
  <a class="toolbar"  href="www.mydomain.com/register">
     Save &amp; Close
  </a>
</li>

I have a selector for the anchor tag, $$('#toolbar-save a'). By using this selector how can I trigger the click event ? or any other way you can suggest ? thanks in advance.

3
  • @pXL that's not working getting error $$(...).click is not a function Commented Jun 13, 2013 at 21:43
  • Are you trying to do this with Prototype or jQuery? (Why the 'jquery' tag?) Commented Jun 13, 2013 at 21:44
  • @nnnnnn how can I write the prototype selector ? Commented Jun 13, 2013 at 21:46

1 Answer 1

12
$$('#toolbar-save a')[0].click();

FIDDLE

Sign up to request clarification or add additional context in comments.

4 Comments

Edited the answer, and added a fiddle. Using $$ to select elements returns an array, so you either have to select the first element in the collection (or whichever you'd like) or iterate.
fire and simulate is getting the same error, working fine with $$('#toolbar-save a')[0].click()
@Nisam - you're right, I stopped testing when I got the selector right, but was sure simulate() would work, but it did'nt. click() does however work when you get the right element.
If you need get element by id method $('toolbar-save a') return one object in prototype by id without # Method $$('#toolbar-save a') get array of elements with selector $$('#toolbar-save a')[0] retrieve first element in array, this way mostly use when need get elements by class or tagname

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.