manix Posted August 5, 2011 Share Posted August 5, 2011 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> Quote Link to comment https://forums.phpfreaks.com/topic/243921-jquery-function/ Share on other sites More sharing options...
AyKay47 Posted August 5, 2011 Share Posted August 5, 2011 you will want soemthing like this <script type="text/javascript"> function showvotes(id){ $(id).hover( function () { $("show"+id).show(500); }, function () { $("show"+id).hide(500); }); } Quote Link to comment https://forums.phpfreaks.com/topic/243921-jquery-function/#findComment-1252483 Share on other sites More sharing options...
manix Posted August 5, 2011 Author Share Posted August 5, 2011 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); }); } Quote Link to comment https://forums.phpfreaks.com/topic/243921-jquery-function/#findComment-1252486 Share on other sites More sharing options...
trq Posted August 5, 2011 Share Posted August 5, 2011 You really should probably start over with jQuery. Modern JavaScript frameworks have selector engines a which allow you to use css3 selectors to select elements within a document. This means you no longer need to attach events to elements within your markup like you are doing. Quote Link to comment https://forums.phpfreaks.com/topic/243921-jquery-function/#findComment-1252489 Share on other sites More sharing options...
manix Posted August 5, 2011 Author Share Posted August 5, 2011 Yeah I know but I don't know how to pass a variable if I don't use events in the elements.. Quote Link to comment https://forums.phpfreaks.com/topic/243921-jquery-function/#findComment-1252494 Share on other sites More sharing options...
trq Posted August 5, 2011 Share Posted August 5, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/243921-jquery-function/#findComment-1252496 Share on other sites More sharing options...
AyKay47 Posted August 5, 2011 Share Posted August 5, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/243921-jquery-function/#findComment-1252499 Share on other sites More sharing options...
trq Posted August 5, 2011 Share Posted August 5, 2011 Ha! So did I in my simple example. That's what you get for working with Mootools all day. I haven't programmed in jQuery for about 4 months. Quote Link to comment https://forums.phpfreaks.com/topic/243921-jquery-function/#findComment-1252504 Share on other sites More sharing options...
manix Posted August 5, 2011 Author Share Posted August 5, 2011 Actually I did some improvements and I removed the events from the divs, actually the function is alot simpler now $('.vic').hover( function () { $('#show'+$(this).attr('id')).show(600); }, function () { $('#show'+$(this).attr('id')).hide(); }); Quote Link to comment https://forums.phpfreaks.com/topic/243921-jquery-function/#findComment-1252508 Share on other sites More sharing options...
AyKay47 Posted August 5, 2011 Share Posted August 5, 2011 Ha! So did I in my simple example. That's what you get for working with Mootools all day. I haven't programmed in jQuery for about 4 months. ha..i wasn't fully awake when I wrote that example.. Quote Link to comment https://forums.phpfreaks.com/topic/243921-jquery-function/#findComment-1252558 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.