2
    <input  type="button" onclick="???"    id="1" value="Button1"   />

Without knowing what the name of the function in the onclick attribute, can I take the function from the onclick attribute and call it in javascript? If so, how can I do that?

3 Answers 3

2

If you just want to trigger click event which will call the onclick function, you can do something like this, using jquery

$('#1').click()
Sign up to request clarification or add additional context in comments.

Comments

1

If you're using jQuery:

eval($('#1').attr('onclick'));

Comments

1

This should work, NOTE: IDs are not allowed to start with a number:

<input  type="button" onclick="???"    id="Button1 value="Button1"   />

document.getElementById("Button1").onclick();

Example

The way to do it in jQuery would be $('#Button1').trigger('click') using trigger

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.