Thursday 15 July 2010

html - jQuery - Change CSS of one element from many with same class identification -



html - jQuery - Change CSS of one element from many with same class identification -

i working around simple jquery script changing backgroud color of element when clicked.

here code:

<script src="//code.jquery.com/jquery-1.10.2.js"></script> <div class="radio">text1</div> <div class="radio">text2</div> <div class="radio">text3</div> <div class="radio">text4</div>

i want next happen:

i click on "text1" , div changing background color reddish , remain red.

i click on "text2" , background color of "text1" going white , background color of "text2" going , remain red.

i hope give description.

can help me create ?

thanks in advance!

class="snippet-code-js lang-js prettyprint-override">$('.radio').click(function(){ $('.red').removeclass('red'); $(this).addclass('red'); }); class="snippet-code-css lang-css prettyprint-override">.red{ background-color: red; } class="snippet-code-html lang-html prettyprint-override"><script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> <div class="radio">text1</div> <div class="radio">text2</div> <div class="radio">text3</div> <div class="radio">text4</div>

jquery html css

No comments:

Post a Comment