Cyto Posted March 31, 2012 Share Posted March 31, 2012 Hey, I'm trying to hover a id element with the same name, example: id="C_22" equeals id="C_22" both get class hlh I got this so far, but it only hovers 1 element with the same id. I want both to have the class hlh, only one gets it. var hlhid = $('[id^="D_"]'); $(hlhid).hover( function () { if(this == this){ $(this).addClass("hlh"); } }, function () { if(this == this){ $(this).removeClass("hlh"); } } ); Cyto Quote Link to comment https://forums.phpfreaks.com/topic/260066-same-id-hover/ Share on other sites More sharing options...
trq Posted March 31, 2012 Share Posted March 31, 2012 id's must be unique. Quote Link to comment https://forums.phpfreaks.com/topic/260066-same-id-hover/#findComment-1332983 Share on other sites More sharing options...
Cyto Posted March 31, 2012 Author Share Posted March 31, 2012 id's must be unique. I know, but im equaling the names not styling with it. Quote Link to comment https://forums.phpfreaks.com/topic/260066-same-id-hover/#findComment-1332985 Share on other sites More sharing options...
trq Posted March 31, 2012 Share Posted March 31, 2012 What? Quote Link to comment https://forums.phpfreaks.com/topic/260066-same-id-hover/#findComment-1332986 Share on other sites More sharing options...
Cyto Posted March 31, 2012 Author Share Posted March 31, 2012 Did you read my first post? Quote Link to comment https://forums.phpfreaks.com/topic/260066-same-id-hover/#findComment-1332988 Share on other sites More sharing options...
trq Posted March 31, 2012 Share Posted March 31, 2012 Yes I read your post. It makes little sense. Quote Link to comment https://forums.phpfreaks.com/topic/260066-same-id-hover/#findComment-1332991 Share on other sites More sharing options...
Andy-H Posted March 31, 2012 Share Posted March 31, 2012 What Thorpe is saying is that having two or more elements with the same ID is against W3C standards, use classes instead. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html lang="en"> <head> <title>Test</title> <!-- META //--> <meta name="description" content="" > <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" > <!-- JQUERY //--> <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.min.js"></script> <script type="text/javascript"> <!-- $(document).ready(function() { $('[class^="d_"]').bind({ 'mouseenter' : function() { $('.'+ $(this).attr('class')).css({ color : '#f00', fontWeight : 'bold' }); }, 'mouseleave' : function() { $('.'+ $(this).attr('class')).css({ color : '#000', fontWeight : 'normal' }); } }); }); //--> </script> </head> <body> <span class="d_22">Test</span> <span class="d_23">Test</span> <span class="d_22">Test</span> <span class="d_23">Test</span> <span class="d_22">Test</span> <span class="d_23">Test</span> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/260066-same-id-hover/#findComment-1332994 Share on other sites More sharing options...
Cyto Posted March 31, 2012 Author Share Posted March 31, 2012 What Thorpe is saying is that having two or more elements with the same ID is against W3C standards, use classes instead. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html lang="en"> <head> <title>Test</title> <!-- META //--> <meta name="description" content="" > <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" > <!-- JQUERY //--> <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.min.js"></script> <script type="text/javascript"> <!-- $(document).ready(function() { $('[class^="d_"]').bind({ 'mouseenter' : function() { $('.'+ $(this).attr('class')).css({ color : '#f00', fontWeight : 'bold' }); }, 'mouseleave' : function() { $('.'+ $(this).attr('class')).css({ color : '#000', fontWeight : 'normal' }); } }); }); //--> </script> </head> <body> <span class="d_22">Test</span> <span class="d_23">Test</span> <span class="d_22">Test</span> <span class="d_23">Test</span> <span class="d_22">Test</span> <span class="d_23">Test</span> </body> </html> Ok, thx. Quote Link to comment https://forums.phpfreaks.com/topic/260066-same-id-hover/#findComment-1333029 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.