can i get help in .click jquery?

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
mekha
Forum Contributor
Posts: 112
Joined: Sat Mar 31, 2012 6:50 am

can i get help in .click jquery?

Post by mekha »

can i get help in .click jquery?
-----
i have this easy code:

Code: Select all

<?php
require_once("functions.php");
if(isset($_GET['ID']))
$arts_id = $_GET['ID'];
else
header('Location: index.php');
?>
<?php
$sqlphotos=mysql_query("SELECT pages_pic,pages_pic2,pages_pic3,pages_pic4 FROM pages WHERE pages_id=".$arts_id);
$resultphotos=mysql_fetch_assoc($sqlphotos);


?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <title> New Document </title>
  <meta name="Generator" content="EditPlus">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
  <script type="text/javascript" src="jquery-1.7.2.min.js"></script>
  <script type="text/javascript">
$(document).ready(function(){

 









})
  </script>
 </head>

 <body>
  <a class="click"><img border="0" src="<?php echo $resultphotos['pages_pic'] ?>" width="152" height="171"></a></br></br>
    <a class="click"><img border="0" src="<?php echo $resultphotos['pages_pic2'] ?>" width="152" height="171"></a></br></br>
	  <a class="click"><img border="0" src="<?php echo $resultphotos['pages_pic3'] ?>" width="152" height="171"></a></br></br>
	    <a class="click"><img border="0" src="<?php echo $resultphotos['pages_pic4'] ?>" width="152" height="171"></a></br></br></br></br>
		  <a class="clicked"><img border="0" src="<?php echo $resultphotos['pages_pic2'] ?>" width="500" height="500"></a>
 </body>
</html>
now in jquery...i need when i click on the four images that have class="click",the source in a image that have class="clicked" be changed to the source of the image we clicked on it (that have class="click")..can u help me please ?
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: can i get help in .click jquery?

Post by pickle »

Use the .on() method to attach a listener to each <img>. In that listener, use attr() to get the "src" attribute, then use the prop() function to set the src attribute on the main image.

Some notes: The "click" event fires on any element, not just <a> tags. You don't need to wrap each thumbnail in an <a> tag, just give each thumbnail a class of "click" and use that in your selector.

You similarly don't need to wrap your main image in an <a> tag. And, since there's only one, you should give it an ID, not a class. That will allow jQuery to find the image quicker.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply