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 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. 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. 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? 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? 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. 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> 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. Link to comment https://forums.phpfreaks.com/topic/260066-same-id-hover/#findComment-1333029 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.