jquery assign onclick for li from a link

后端 未结 5 1009
长情又很酷
长情又很酷 2020-12-14 13:30

I have a list of items

5条回答
  •  忘掉有多难
    2020-12-14 13:59

    Are you doing this so the whole li block is a clickable link instead of just the a element? If so, you could easily do this with CSS instead.

    HTML:

    
    
        Testing Block Elements
        
    
    
    
        
    
    
    

    CSS:

    #menu {
        list-style: none;
        padding: 0;
        margin: 0;
    }
    
    #menu li {
        /* Added to show the whole li element will be a clickable link. */
        width: 250px;
        border: 1px solid #000000;
    }
    
    #menu li a {
        display: block;
    }
    

    EDIT:

    And by doing this, you only need to attach the click event to the a tag if you really need to do some javascript when the user clicks on it.

提交回复
热议问题