Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
<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?
If you just want to trigger click event which will call the onclick function, you can do something like this, using jquery
$('#1').click()
Add a comment
If you're using jQuery:
eval($('#1').attr('onclick'));
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
$('#Button1').trigger('click')
Required, but never shown
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.
Explore related questions
See similar questions with these tags.