[jQuery] Re: A better way of writing this code?
But CSS :hover will not work in IE6. So better use script On May 15, 9:26 am, RobG rg...@iinet.net.au wrote: On May 15, 11:35 am, Calvin cstephe...@gmail.com wrote: Hi, I was able to get this script to work and was wondering if there was a better/proper/more efficient way of writing it. Here is the script: $(document).ready(function() { $('li.a').hover(function() { $(this).addClass('move'); }); $('li.a').mouseLeave(function() { $(this).removeClass('move'); )}; )}; Use the CSS a:hover pseudo-class and set your style rules there, no script required. li a:hover { /* insert rules */ } URL:http://www.w3.org/TR/CSS2/selector.html#x32 -- Rob
[jQuery] Re: A better way of writing this code?
$(function() { $(#myid).hover(function() { // when mouse is over element }, function() { // else }); }); On Fri, May 15, 2009 at 9:22 AM, Karthikraj karthik271...@gmail.com wrote: But CSS :hover will not work in IE6. So better use script On May 15, 9:26 am, RobG rg...@iinet.net.au wrote: On May 15, 11:35 am, Calvin cstephe...@gmail.com wrote: Hi, I was able to get this script to work and was wondering if there was a better/proper/more efficient way of writing it. Here is the script: $(document).ready(function() { $('li.a').hover(function() { $(this).addClass('move'); }); $('li.a').mouseLeave(function() { $(this).removeClass('move'); )}; )}; Use the CSS a:hover pseudo-class and set your style rules there, no script required. li a:hover { /* insert rules */ } URL:http://www.w3.org/TR/CSS2/selector.html#x32 -- Rob
[jQuery] Re: A better way of writing this code?
:hover does work in IE6, it's just limited to a elements. Jonathan Karthikraj wrote: But CSS :hover will not work in IE6. So better use script On May 15, 9:26 am, RobG rg...@iinet.net.au wrote: On May 15, 11:35 am, Calvin cstephe...@gmail.com wrote: Hi, I was able to get this script to work and was wondering if there was a better/proper/more efficient way of writing it. Here is the script: $(document).ready(function() { $('li.a').hover(function() { $(this).addClass('move'); }); $('li.a').mouseLeave(function() { $(this).removeClass('move'); )}; )}; Use the CSS a:hover pseudo-class and set your style rules there, no script required. li a:hover { /* insert rules */ } URL:http://www.w3.org/TR/CSS2/selector.html#x32 -- Rob
[jQuery] Re: A better way of writing this code?
On May 15, 5:22 pm, Karthikraj karthik271...@gmail.com wrote: But CSS :hover will not work in IE6. So better use script Rubbish. The OP wants to use it on an A element, which supports :hover in probably every browser since Navigator and IE 4, if not older. -- Rob
[jQuery] Re: A better way of writing this code?
as rob said, unless the OP is using the anchor's class itself in conjunction with some other jquery selector at that point, the OP would be better off just using :hover. jquery is awesome, but using it to do stuff CSS already does better is considerably less awesome. On May 15, 9:22 am, RobG rg...@iinet.net.au wrote: On May 15, 5:22 pm, Karthikraj karthik271...@gmail.com wrote: But CSS :hover will not work in IE6. So better use script Rubbish. The OP wants to use it on an A element, which supports :hover in probably every browser since Navigator and IE 4, if not older. -- Rob
[jQuery] Re: A better way of writing this code?
On May 15, 3:24 pm, ryan.j ryan.joyce...@googlemail.com wrote: as rob said, unless the OP is using the anchor's class itself in conjunction with some other jquery selector at that point, the OP would be better off just using :hover. jquery is awesome, but using it to do stuff CSS already does better is considerably less awesome. And less efficient which was a primary concern of the OP :)
[jQuery] Re: A better way of writing this code?
Hi Calvin, I think what you're looking for is something like this, as James said. $(li a).hover(function(){ $(this).addClass(move); }, function() { $(this).removeClass(move); }); Of course, include document ready function. -Jon Thomas On May 14, 8:35 pm, Calvin cstephe...@gmail.com wrote: Hi, I was able to get this script to work and was wondering if there was a better/proper/more efficient way of writing it. Here is the script: $(document).ready(function() { $('li.a').hover(function() { $(this).addClass('move'); }); $('li.a').mouseLeave(function() { $(this).removeClass('move'); )}; )}; Thanks for your time, Calvin Stephens
[jQuery] Re: A better way of writing this code?
what about that ? $(li a).hover(function(){ $(this).toggleClass(move); }); On May 15, 4:42 pm, Jthomas wjthom...@yahoo.com wrote: Hi Calvin, I think what you're looking for is something like this, as James said. $(li a).hover(function(){ $(this).addClass(move); }, function() { $(this).removeClass(move); }); Of course, include document ready function. -Jon Thomas On May 14, 8:35 pm, Calvin cstephe...@gmail.com wrote: Hi, I was able to get this script to work and was wondering if there was a better/proper/more efficient way of writing it. Here is the script: $(document).ready(function() { $('li.a').hover(function() { $(this).addClass('move'); }); $('li.a').mouseLeave(function() { $(this).removeClass('move'); )}; )}; Thanks for your time, Calvin Stephens
[jQuery] Re: A better way of writing this code?
While $(li a).hover(function(){ $(this).addClass(move); }, function() { $(this).removeClass(move); }); works well in theory, I've found that $(li a).hover(function(){ $(li a).removeClass(move); $(this).addClass(move); }, function() { $(this).removeClass(move); }); is necessary in practice. Assuming of course that you can't use the CSS solution which is obviously preferable. _jason On May 15, 8:09 am, benoit v. benv...@gmail.com wrote: what about that ? $(li a).hover(function(){ $(this).toggleClass(move); }); On May 15, 4:42 pm, Jthomas wjthom...@yahoo.com wrote: Hi Calvin, I think what you're looking for is something like this, as James said. $(li a).hover(function(){ $(this).addClass(move); }, function() { $(this).removeClass(move); }); Of course, include document ready function. -Jon Thomas On May 14, 8:35 pm, Calvin cstephe...@gmail.com wrote: Hi, I was able to get this script to work and was wondering if there was a better/proper/more efficient way of writing it. Here is the script: $(document).ready(function() { $('li.a').hover(function() { $(this).addClass('move'); }); $('li.a').mouseLeave(function() { $(this).removeClass('move'); )}; )}; Thanks for your time, Calvin Stephens
[jQuery] Re: A better way of writing this code?
$(document).ready(function() { $('li.a').hover( function() { $(this).addClass('move'); }, function() { $(this).removeClass('move'); } )}; )}; On May 14, 3:35 pm, Calvin cstephe...@gmail.com wrote: Hi, I was able to get this script to work and was wondering if there was a better/proper/more efficient way of writing it. Here is the script: $(document).ready(function() { $('li.a').hover(function() { $(this).addClass('move'); }); $('li.a').mouseLeave(function() { $(this).removeClass('move'); )}; )}; Thanks for your time, Calvin Stephens
[jQuery] Re: A better way of writing this code?
Slight typo near the end. $(document).ready(function() { $('li.a').hover( function() { $(this).addClass('move'); }, function() { $(this).removeClass('move'); } ); )}; On May 14, 3:47 pm, James james.gp@gmail.com wrote: $(document).ready(function() { $('li.a').hover( function() { $(this).addClass('move'); }, function() { $(this).removeClass('move'); } )}; )}; On May 14, 3:35 pm, Calvin cstephe...@gmail.com wrote: Hi, I was able to get this script to work and was wondering if there was a better/proper/more efficient way of writing it. Here is the script: $(document).ready(function() { $('li.a').hover(function() { $(this).addClass('move'); }); $('li.a').mouseLeave(function() { $(this).removeClass('move'); )}; )}; Thanks for your time, Calvin Stephens
[jQuery] Re: A better way of writing this code?
Thanks James! On Thu, May 14, 2009 at 6:49 PM, James james.gp@gmail.com wrote: Slight typo near the end. $(document).ready(function() { $('li.a').hover( function() { $(this).addClass('move'); }, function() { $(this).removeClass('move'); } ); )}; On May 14, 3:47 pm, James james.gp@gmail.com wrote: $(document).ready(function() { $('li.a').hover( function() { $(this).addClass('move'); }, function() { $(this).removeClass('move'); } )}; )}; On May 14, 3:35 pm, Calvin cstephe...@gmail.com wrote: Hi, I was able to get this script to work and was wondering if there was a better/proper/more efficient way of writing it. Here is the script: $(document).ready(function() { $('li.a').hover(function() { $(this).addClass('move'); }); $('li.a').mouseLeave(function() { $(this).removeClass('move'); )}; )}; Thanks for your time, Calvin Stephens
[jQuery] Re: A better way of writing this code?
On May 15, 11:35 am, Calvin cstephe...@gmail.com wrote: Hi, I was able to get this script to work and was wondering if there was a better/proper/more efficient way of writing it. Here is the script: $(document).ready(function() { $('li.a').hover(function() { $(this).addClass('move'); }); $('li.a').mouseLeave(function() { $(this).removeClass('move'); )}; )}; Use the CSS a:hover pseudo-class and set your style rules there, no script required. li a:hover { /* insert rules */ } URL: http://www.w3.org/TR/CSS2/selector.html#x32 -- Rob