Jump to content

Same id hover


Cyto

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

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