How about you have a document like this:

HTML

<p class="swapme white"></p>
<p class="swapme black"></p>
<p class="swapme trans"></p>

JavaScript
$(function(){
 $("p.swapme").click(function(){
   switchColor(this);
 });
});

Note the use of multiple classes.

- jake

On 5/30/07, cfdvlpr <[EMAIL PROTECTED]> wrote:


I have several lines of code that are almost identical like this:

$(function(){
        $('p.productColorWhite').click(function(){
                switchColor(this);
        });
        $('p.productColorTranslucent').click(function(){
                switchColor(this);
        });
        $('p.productColorBlack').click(function(){
                switchColor(this);
        });
});

How can I write this in a way that is less repetitive or uses better
practice?

I'd like to do something like this:
$(function(){
        $('p.productColor*').click(function(){
                switchColor(this);
        });
});

But, I know that is not correct syntax...


Reply via email to