I have a button that, apart from doing something, replaces its own ID, then when pressed It does something different as it is a different button. The problem is that for the first time after changing the ID, the previous button click function throws an error because the id no longer exists.
$ ("# button1"). Click (function () {// some documents. GetElementById ("# button1"). Id = "button2";}); $ ("# Button2") Click (function () {// a different document .getElementById ("# button2"). Id = "button1";});
You can complete it by using jQuery, but the comments are outlined in As it is possible, you should be an indication to change your attitude, however, if you have to do this, here's a solution using jQuery's 'On'.
$ ('# outerContainer'). ('Click', '# button1', function () {warning ('clicked button 1!'); $ (This) .attr ('id', 'button2');}); $ ('# OuterContainer') ('Click', '# button2', function () {warning ('button 2 clicked!'); $ (This) .attr ('id', 'button1');}); Some extra notes - If you take the Smash approach, then you will need to use the 'o' function so that the bytes can change to change the events, unless you have not. Set the onclick attribute directly to the html tag Christian's approach gives you click functions such as the ones you are currently using.
Comments
Post a Comment