Loading ...

Selection based on multi attributes with jquery

Who is online?  0 guests and 0 members
home  »  forums   »  asp.net topics   »  client side web development   » Selection based on multi attributes with jquery

Selection based on multi attributes with jquery

Posts under the topic: Selection based on multi attributes with jquery

Posted: 4/2/2010

Lurker 170  points  Lurker
  • Joined on: 10/17/2009
  • Posts: 34

I have various anchor tags on my page . Now I need to select only those anchors which have class name "highlight" and id containing "menu" text.

I need to do the above with jquery . I know this syntax

 

$("a[class=highlight]")

 

But the issue is how to match the other one.


Posted: 4/19/2010

Guru 16518  points  Guru
  • Joined on: 4/19/2009
  • Posts: 483
  Answered

<html xmlns="http://www.w3.org/1999/xhtml" >
<head >
    <title></title>
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script>

</head>
<body>
    
  <a href="#" id="menu1" class="light">a1</a>
  <a href="#" id="a2" class="highlight">a2</a>
  <a href="#" id="menu2" class="highlight">a3</a>
  <a href="#" id="a4" >a4</a>
  <a href="#" id="menu3" class="highlight">a5</a>
    
</body>
    <script type="text/javascript">
        $(function ()
        {
            var anchors = $('a[id*=\'menu\'][class=\'highlight\']');

            //now test it 
            $.each(anchors, function (index, anchor)
            {
                alert(anchor.id);
            });
        });
    
    </script>
</html>


Page 1 of 1 (2 items)