views:

28

answers:

3

All,

In the code below,Could u please tell me that how code should be changed such that on mouse over hyperlink,div should appear and on the right side of the hyperlink

<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"&gt;&lt;/script&gt;

<script>
$(document).ready(function(){
$('a.moreDetails').hover(function() {
$(this).next().toggle('fast');
});
});

</script>  

<body>
<a href="#" class="moreDetails">(details)</a>
<div class="details">User 1</div>
</body>
</html>

Thanks..............

A: 

hover() takes two arguments: a callback for when it's activated and another when its deactivated so:

$("a.moreDetails").hover(function() {
  $(this).next("div.details").stop().show("fast");
}, function() {
  $(this).next("div.details").stop().show("slow");
});

You'll note that I'm calling stop(). That's a good habit to get into when using animations otherwise you can get unintended visual artifacts from queueing animations.

Edit: Appearing next to the element has some difficulties. You can change the CSS:

div.details { display: inline; }

and it will appear next to the link but then the jQuery effects won't really work correctly because they tend to set things to display: block. If you don't want or need the effect you can just use a class:

div.details { display: inline; }
div.hidden { display: none; }

and then:

$("a.moreDetails").hover(function() {
  $(this).next("div.details").addClass("hidden");
}, function() {
  $(this).next("div.details").removeClass("hidden");
});
cletus
Thanks...but how to make it appear next to the hyperlink and not below
Hulk
@Hulk: see my update.
cletus
Thanks..........................
Hulk
+1  A: 

jQuery's hover method takes two function inputs:

$("a.moreDetails").hover(
  function(){
    $(this).next().show('fast');
  },
  function(){
    $(this).next().hide('fast');
  }
);

You also appear to be missing your closing </head> tag. Getting your element to appear next to your link will require some markup-changes, javascript manipulation, or some css rules. You could make this minor change:

<a href="#" class="moreDetails">(details)</a>
<span class="details">User 1</span>
Jonathan Sampson
Thanks...but how to make it appear next to the hyperlink
Hulk
@Hulk: You can change it from a `div` to a `span`, or you can add `display:inline` to its styling.
Jonathan Sampson
Thanks......................
Hulk
@Hulk: You're welcome. Keep up the great work!
Jonathan Sampson
A: 

hover takes 2 functions as parameters, to handle over and out. you should show in the first and hide in the second. then your div, unless its class makes it inline, should probably be a span

Scott Evernden