last day (15 days later) » 

7:48 PM
2
A: Disable and Enable Click event using Jquery

AtheistP3aceIf you are going to continually remove and add the event I would move the click functionality to a function you can reuse. function myOnClick () { $(this).addClass("btn-primary").siblings().removeClass("btn-primary"); viewtype = this.id; $(this).blur(); showPage(); } Then you c...

 
Thanks for your suggestion, can we do without function ?
 
Sure you can continually use an anonymous function if you want.
 
Do we need pass the current object ie this() to myOnclick function ?
 
this is the context of the function, you don't need to pass it. It's just there and in your case references the element that was clicked.
 
Using your suggestion ,we can disable the click event for the all button and vice versa,but my requirement is enable/disable the event based on the conditions, so that i am using off method in the loop.
The given below code used to disable the click event for Cricket/Tennis .var disableOptionsTabs=["C","T"]; disableButtons(disableOptionsTabs);
 
7:48 PM
Yes, I gave you an example on how to disable the 'click' event. Then I also showed you how to properly use your disableButtons method to disable buttons that are in the list you pass it. Did you read the entire answer?
Ah see there is some code you didn't include. As I said in my answer if that list was actual DOM elements loop using this. Since those are just strings which I assume are referencing IDs than go back to your old loop using $('#' + value).off('click')
 
yes perfect.
it is not working brother.
the same issue i am facing , i can able to disable the click event and could not able bind the click event for the button
Could you please help me ?
 
Hi
Sorry stepped away from desk
So I am confused about the issue. The binding works the first time but after you remove it, you are unable to rebind it?
Can you show me the latest code you have?
 
yes sure.
To enable the click event
I am using below code
function enableButtons(mybuttons){
$(".btn-group > .btn").on("click", myOnClick);

}
the above line of code is not working as we expected.
 
8:07 PM
OK simple questions first: is the myOnClick function defined?
 
Initially i am disabling all the other functionality , then i am enabling based on the coditions
function myOnClick () {
//alert('testing');
$(this).addClass("btn-primary").siblings().removeClass("btn-primary");
viewtype = this.id;
$(this).blur();
reload();
}
I have included
but i am not getting alert message after i bind it
$.each( mybuttons, function( key,value )
{ $( "#" + value ).on("click",myOnClick); }
);
I have tried with above set of the lines inside the enableButton method
I am using the above .. because i want to bind the click event for the particular page
so that i am adding the click events based on the id.
 
look at this
or this where i loop to attach events as well
 
yes sure
Thanks a lot for your help , and quick turn around with sample.
function enableButtons (mybuttons){
$(".btn-group > .btn").on("click", myOnClick);
}
The above set of code used to enable the click event for all the buttons
I need specify buttons only
do we need to pass the id in on method ?
$(".btn-group > .btn").on(" c. click", myOnClick); like this ?
 
8:32 PM
Do you mean that this selector $(".btn-group > .btn") could return buttons you dont want to attach events to?
 
yes i want attach the event for particular button
based on the role
say for example , i will some user to clik and show the page of cricket,tennis
some of them not allowed to see the page.
i will give some more example.
Based on the date time selection , user can able to see the daily /weekly /monthly records
if the user selects the day .. he /she is not allowed to click the weekly records
if the user select weekly ,he /she is allowed to click daily/weekly records
 
Thats more an option of business logic. You need to give yourself some indicator of what buttons to attach the event to. If you generate the HTML you could drop a class on only the buttons to attach the event to. If not you could create a function to attach the events and pass a list of buttons that should only receive the event. So many ways to do it and I am not very familiar with your entire setup its hard to say how "you" should do it
 
8:49 PM
yes i agree.
but what i am expecting / or searching from internet is to enable the click event which is i revoked earlier .
$(".btn-group > .btn").on(" c. click", myOnClick); // 1 option
$(".btn-group > .btn > c").on("click", myOnClick); // 2 option
i am checking with above two options.
 
option 1 and option 2 are two totally different things
 
i am not sure about the syntax
oh , then it should not work out .. let me try with out options.
 
option 1 is adding a namespace on to the click event so you can remove/reference it based on namespace later. option 2 is saying the element with class btn has a direct descendant element with tag c
 
thats great
since i am new UI development, i just traveling based on the google / and friend suggestion / recommentation
since i am new to*
i hope you are understand my requirement , let me share some another approach to achieve the same.
no problem , i will spend some extra time and i will complete it . :)
 
ok good luck. as i said conditionally attaching events to some things vs others isn't hard but there are so many ways to do it and you need to know more about the entire setup to decide which way to go
 
9:03 PM
Thanks AtheistP3ace for support. you are great.
let me try with conditionally attaching event.
 
good luck!!
 

last day (15 days later) »