0
$('#target a').attr("onClick=", link);

for some reason I have to do this one, but it says Failed to execute 'setAttribute' on 'Element': 'onclick=' is not a valid attribute name.

2
  • 1
    what is link? is it a function? Commented Sep 19, 2014 at 6:44
  • 1
    Why not just ` $('#target a').on('click', link) ;`? Commented Sep 19, 2014 at 6:45

2 Answers 2

3
$('#target a').attr("onClick", link);

This is what you're looking for.

Though you could use:

$('#target a').on('click', link);

Please note that link should be a function and not just a url.

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

Comments

0

You don't need attribute editing. You just need to set 'click' event handler.

$('#target a').click(link);

where link is a handling function.

Comments

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.