jquery - Assign 2 actions to one html button -


im trying assign 2 actions 1 button in webpage:

  1. send message arduino run server
  2. change color of button toggleclass can see if it's on/off

code:

function autoon() {     $('#content').load('/arduino/autoon');     $("button#autoon").click(function () {         $(this).toggleclass("selected");     });       } 

now color of buttons change need click button 2 times change color.

why don't change button's class inside autoon function?

$("#autoon").toggleclass("selected"); 

so autoon function become:

function autoon()     {         $('#content').load('/arduino/autoon');         $("#autoon").toggleclass("selected");     } 

Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -