Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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