Jump to content

Jquery function


manix

Recommended Posts

Hello,

 

Since I completely fail at writing jquery I really need some help getting this done,

 

I have some divs with the same class and individual ID's, those divs contain a bunch of items, but one line needs to be hidden and when the mouse is over the div only then show this line, In order to do that I figured I need to pass the div's ID to the jquery function so I can access the exact span I need to show and this is what I came up with

 

while($row = mysql_fetch_assoc($result))
{
         .........
         <div id='$id' class='vic' onmouseover='showvotes(this.id);' onmouseout='showvotes(this.id);'>
         <blockquote style='font-family:comic sans ms;'>$vic</blockquote>
 <span id='show$id' style='display:none'>$vote $ocenki гласа</span>
         ..........
         }

 

and the Jquery as it follows

 

<script type="text/javascript">
$(document).ready(function() {
  function showvotes(id) {
    $('#show'+id).toggle(500);
}
});

</script>

Link to comment
https://forums.phpfreaks.com/topic/243921-jquery-function/
Share on other sites

doesn't really work, I just want to explain a little simpler

 

<div class='vic' id='$id'>

<span id='show$id'></span>

</div>

 

when I hover over a div with class 'vic' it's ID is being sent to the function so the span with id 'show'+div's id gets shown/hidden

 

EDIT: Oh a little modification and it worked now, thanks dude :)

 

function showvotes(id){
$('#'+id).hover(  function () 
{    $('#show'+id).show(500);  },   
function () { $('#show'+id).hide(500);  });
}

Link to comment
https://forums.phpfreaks.com/topic/243921-jquery-function/#findComment-1252486
Share on other sites

It's quite simple.

 

Given some simple markup:

 

<span id="foo">here is some text</span>

 

To retrieve the element you would use:

 

var element = $('foo');

 

To get the text within that element:

 

var text = $('foo').html();

 

There are heaps of good jQuery tutorials around, you really should spend a little time getting familiar.

Link to comment
https://forums.phpfreaks.com/topic/243921-jquery-function/#findComment-1252496
Share on other sites

doesn't really work, I just want to explain a little simpler

 

<div class='vic' id='$id'>

<span id='show$id'></span>

</div>

 

when I hover over a div with class 'vic' it's ID is being sent to the function so the span with id 'show'+div's id gets shown/hidden

 

EDIT: Oh a little modification and it worked now, thanks dude :)

 

function showvotes(id){
$('#'+id).hover(  function () 
{    $('#show'+id).show(500);  },   
function () { $('#show'+id).hide(500);  });
}

yeah i forgot the "#" symbol to state that they are id's..my mistake

Link to comment
https://forums.phpfreaks.com/topic/243921-jquery-function/#findComment-1252499
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.