Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.