Dynamic Selectors with Jquery with php while loop

Posted by Anders Kitson on Stack Overflow See other posts from Stack Overflow or by Anders Kitson
Published on 2010-06-06T21:18:06Z Indexed on 2010/06/06 21:22 UTC
Read the original article Hit count: 312

Filed under:
|
|
|

I have a while loop which creates a list of anchor tags each with a unique class name counting from 1 to however many items there are. I would like to change a css attriubute on a specific anchor tag and class when it is clicked so lets say the background color is changed. Here is my code

while($row = mysql_fetch_array($results)){
 $title = $row['title'];
 $i++;
 echo "<a class='$i'>$title</a>

}

I would like my jquery to look something like this, it is obviously going to be more complicated than this I am just confused as where to start.

$(document).ready(function() {
$('a .1 .2 .3 .4 and so on').click(function() {
$('a ./*whichever class was clicked*/').css('background':'red');
        });
   });

© Stack Overflow or respective owner

Related posts about php

Related posts about jQuery