简体   繁体   中英

Changing cursor by attribute

I've got kind of stuck in the following. In my website I have a dropdown menu. The main item, that causes the dropdown menu to collapse, is not clickable. However, I want to change the cursor of that item to the normal, but make sure that the drop down menu still has the 'hand' cursor.

Html would be:

<ul> 
  <li>
    <a href="nice.php">Normal item<a/>
  </li> 
  <li>
    <a href="#">Dropdown initator</a> 
    <ul>
      <li><a href="droppage.php>Dropdown item</a></li>
    </ul> 
  </li> 
 </ul>

So the link with href="#" should have the non-link cursor; the others should have cursor: 'pointer'.

Tried JS but it won't work, it makes the cursor of the dropdown items also the false one:

$('ul li').hover(function() {
   if($(this).find("a").attr("href") === "#"){
      $(this).css('cursor','e-resize');
      $(this).find("a").css('cursor', 'e-resize');
      $(this).find("ul li").css('cursor', 'pointer');
    }
});

It shouldn't make any differences but the page is actually part of a wordpress installation.

Any help is very much appreciated!

Just use CSS.

a[href='#']{
    cursor: e-resize;   
}

DEMO: http://jsfiddle.net/XnNUt/

You can add the following css:

a {
   cursor: pointer;
}

a[href="#"] {
   cursor: default;
}

Set the css property cursor: pointer; for that specific class.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM