Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Manually Calling an event function using JQuery

I want to know if their is an option to call a function that is already assigned to a JQuery event.

For example:

$("#somediv").change(function() { //do something });

I want to be able to manually call that function that was originally assigned to the "somediv" element.

Thanks.

like image 238
Idan Shechter Avatar asked Aug 05 '11 16:08

Idan Shechter


2 Answers

Use trigger:

$("#somediv").trigger("change");
like image 52
PetersenDidIt Avatar answered Oct 28 '22 13:10

PetersenDidIt


<script type="text/javascript">
window.onload = function () {
    $("#somediv").change();
}
</script>

i think this what you want to do .

like image 29
Ancoor D Banerjee Avatar answered Oct 28 '22 13:10

Ancoor D Banerjee