Jump to content

jquery .trigger() add extra parameters to the event type


joymis
 Share

Recommended Posts

Hello,

I have this code

<button class="btn btn-info" onclick="BatchAsign()">Batch</button>

<button class="asign_btn" onclick="Asign({a:'1', b:'2'}, this)">Asign1</button>
<button class="asign_btn" onclick="Asign({a:'2', b:'6'}, this)">Asign2</button>
<button class="asign_btn" onclick="Asign({a:'5', b:'4'}, this)">Asign3</button>

<script>
function BatchAsign(){
	$.each( $('.asign_btn'), function( key, val ) {
		$(this).trigger( "click", ['all'] )
	});
}
  
function Asign(arr, dom, x)
{
  if(x == 'all'){
    // I want do something
  }
}
</script>

When I click BatchAsign button, I want pass a extra parameters to Asign.

I used console.log(x), it's display 'undefined'.

How can I get string 'all' in the function Asign?

thanks.

Edited by joymis
Link to comment
Share on other sites

The jQuery documentation for trigger seems to imply that you need to use the on method or one of its shortcuts to assign the event handler.  That might mean it's not going to work correctly by using event attributes.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...