views:

112

answers:

4

All,

var a='<div id="details"  onmouseover="tip(this)">';

function tip(el)
{
    $(this).mouseover(function() {
    var b="<div id='test'>"+el.innerHTML+"</div>";
    $(b).css("display", "inline");
    });
}

Is anything wrong with the above code? I am trying to display el.innerhtml on mouserover next to the hyperlink

+2  A: 

You need to append the code to your page DOM so it could be displayed. Currently you create a div, set CSS for it but it's still only in memory.

RaYell
Can u please show me the code
Hulk
A: 

You are using $(this) inside your function, maybe it should be $(el)? And you need to do something like $('body').append(b); as well to add the <div> to the DOM.

kb
Can u please show me the code that u r telling
Hulk
Is it that hard to type 'you' and 'are'? Also just looking in the jQuery documentation for append will show you plenty of examples. http://api.jquery.com/append/
Daniel
+4  A: 

Why not try this instead :

 function tip(el) {
     $(this).mouseover(function() {
     $("#test").html(el.innerHTML);
     $("#test").css("display","inline");
     }); }
c0mrade
Doesnt work..............
Hulk
Then you need to clarify what exactly do you want .. you question seems wrong, hence the vote downs
c0mrade
+2  A: 

Try to expand on what you want. Give us a list of requirements spell out exactly what you want. I expect a couple of the down votes will be rescided if you do this.

For my part, try this:

<div id="details">


<script type="text/javascript">
    $(document).ready(function(){
        $("#details").mouseover(function(){
            var $this = $(this);
            $this.append("<div id='test'>"+$this.html()+"</div>");
        });
    })
</script>

To show/hide would have been simple call to .show() or .hide()

If you really wanted this code:

var a='<div id="details"  onmouseover="tip(this)">'; 

Then you would have to append to the DOM:

$(document).append('<div id="details">');

And then bind your event:

$("#details").mouseover(function(){
James Wiseman
Very good answer +1 .. if that is what he wants ..
c0mrade