Link to home
Create AccountLog in
Avatar of peter_coop
peter_coopFlag for United Kingdom of Great Britain and Northern Ireland

asked on

div class error

I am trying to select individual elements when clicked and passed to jquery. What is happening however, is that when clicked all the elements are selected instead of individual elements. Could someone please point out my error. Thanks

php code

mysql_select_db($database_conn, $conn); 
		$query = "SELECT * FROM contact_frm WHERE to_frm = '$_SESSION[kt_name_usr]' AND read_frm = 1 order by date_frm desc"; 
		$result = mysql_query($query) or die(mysql_error()); 
		$a=0; /* VARIABLE*/ 
			if (mysql_num_rows($result)) 
			{
			
				 
				//$rowdate = date("d/m/Y",strtotime($row['destroyed_date'])); 
			
				while($row = mysql_fetch_array($result)) 
				{
			
					$rowdate = date("d/m/Y",strtotime($row['date_frm']));
					$id = $row['id_frm'];
					$from = $row['from_frm'];
					$subject = $row['subject_frm'];
					$message = $row['message_frm'];
					
					echo '<div class="msgTrue" style="background-color:#eee;">' . '<img src="images/sml_new_mail_icon.jpg">' . $subject . '<div style="float:right;margin-right:35px;margin-top:5px;font-size:9px;">' 
. $rowdate . '</div>';
					echo '<br />';
					echo '<span style="font-weight:bold;">' . $from . '</span>';
					
					echo '</div>';
					echo '<br />';
			
				}
			}
			else
			{
				echo '<span style="font-size:11px;font-family:Verdana, Arial, Helvetica, sans-serif;font-weight:normal;margin-left:2px;font-style: italic">' 
. 'There is currently no new mail for you.' 
. '</span>' 
. '<br />';
			}

Open in new window


jquery code

$(function() {
	$(".msgTrue").click(function() {
	//var message = $('#msgTrue').val();
	$(".msgTrue").css("background-color","yellow");
	//$("#msgcontent, #main").show(1000);
	//$("#msgtest").hide(1000);
	});
});

Open in new window

Avatar of Robert Granlund
Robert Granlund
Flag of United States of America image

You are assigning the same class to each element.  So when clicked all of the elements with that class are chosen.
Try giving a clicked div a class instead.
Avatar of Marco Gasi
Try this:

$(function() {
      $(".msgTrue").click(function() {
      $(this).css("background-color","yellow");
      });
});
ASKER CERTIFIED SOLUTION
Avatar of Marco Gasi
Marco Gasi
Flag of Spain image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of peter_coop

ASKER

Thanks very much
Thanks for points, Peter. I found some of our previous 'meetings' here at EE, but I remember something about Google and curl which I didn't find... Anyway, good luck with your project

Marco