user357034
user357034

Reputation: 10981

is there a jquery shortcut for triggering an input

I have to add an input with a name of "btnupdateprice" that I first have to dynamically insert it into the page (hidden of course) and then trigger it. Is there a way to do this without inserting it into the page like the following? A shortcut perhaps?

$("input[type='hidden'][name='ProductCode']").before('<input type="image" border="0" name="btnupdateprice" src="blank_image.gif" style="display: none;">');
$('input[name=btnupdateprice]').trigger('click');

Upvotes: 1

Views: 118

Answers (1)

Dan Manastireanu
Dan Manastireanu

Reputation: 1822

You could try the reverse flow using insertBefore, and the shorthand function click

$('<input type="image" border="0" name="btnupdateprice" src="blank_image.gif" style="display: none;">').insertBefore("input[type='hidden'][name='ProductCode']").click();

If you don't want to add it to the page you can just remove the .insertBefore(...) part.

Upvotes: 2

Related Questions