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

c# - Class in a list -

mysql - Django database model for my website -

ios - How to run a segue on itself OR another viewController -