Pablo G

How Can I Convert Multiple Click Functions Into One?

Asked by Pablo G 2 years ago click function


Devone
0
 
Lets say you have these functions:

$("div#styleswitcher a.green").click(function(){
$("container").css({'background' : 'green'});

)

$("div#styleswitcher a.blue").click(function(){
$("container").css({'background' : 'blue'});

)

$("div#styleswitcher a.red").click(function(){
$("container").css({'background' : 'red'});

)

$("div#styleswitcher a.yellow").click(function(){
$("container").css({'background' : 'yellow'});

)

You can do something like this:

$("#styleswitcher a").click(function ()
{
    $("container").css("background-color", this.className);
});

The background color should be the class name ;)

by Devone 2 years ago

Answer this question

How Can I Convert Multiple Click Functions Into One?

0 errors found:

 
0