How can I do the following in a conditional?
$(function () {
$("[id*='_btnCheck']").click(function () {
var buttonName = $(this).attr('id');
ChannelEvent(buttonName);
});
$("[id*='_btnRuta']").click(function () {
var buttonRuta = $(this).attr('id');
RouteEvent(buttonRuta);
});
});
If I click on a button with the id _btnCheck
then something happens, if I click on a button with the id _btnRuta
then something happens, and finally if I click on a button with the id _btnCliente
then something happens.
My code is functional, but I have been left with this small limitation.
Update:
I'll explain better let's say I have 10 buttons and these are from the group A
, another 10 buttons are from the group B
, another 10 from the group C
.
Each button has a different ID. The code that I have put is to track a key inside the button id. If we place ourselves in the group A
. all buttons have the key: _btnCheck
, but obviously the full ID of a button in group A can be: e1_btnCheck
, Other is e2_btnCheck
, Other is e3_btnCheck
and so on.
So when I click on them, they take me to the same method thanks to the key that contains a part of the ID.
Ok, now, there are many buttons but they are grouped by that key.
When I use :
$(function () {
$("[id*='_btnCheck']").click(function () {
var buttonName = $(this).attr('id');
ChannelEvent(buttonName);
});
});
The button responds to me with I want and guides me to the event, which is then converted to a webmethod in ASP.net.
If I put the code to look for the following groups, B
and C
. The click event is not fired. Only only for the group A
. So I was thinking of making a conditional which might work.
If you have a better idea, welcome. I'm not very good at JS. Thanks.
For what you count, it would be better if you used classes to differentiate the buttons:
This could help you, you just have to add a common class to all your buttons in this case btn , for example:
This is one option: