Loading ...

Find all the anchors which contains # as href

Who is online?  0 guests and 0 members
home  »  forums   »  asp.net topics   »  client side web development   » Find all the anchors which contains # as href

Find all the anchors which contains # as href

Posts under the topic: Find all the anchors which contains # as href

Posted: 3/28/2010

Lurker 235  points  Lurker
  • Joined on: 10/16/2009
  • Posts: 47

Experts,

I need to select all those anchors which contains # as href like

<a href="#">.....</a>

 

I need to do it with jquery.


Posted: 4/5/2010

Starter 710  points  Starter
  • Joined on: 11/11/2009
  • Posts: 34

Posted: 4/19/2010

Guru 16813  points  Guru
  • Joined on: 4/19/2009
  • Posts: 490
  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="a1">a1</a>
  <a href="#" id="a2">a2</a>
  <a href="#abc" id="a3">a3</a>
  <a href="#def" id="a4">a4</a>
  <a href="#" id="a5">a5</a>
    
</body>
    <script type="text/javascript">
        $(function ()
        {
            var anchors = $('a[href=\'#\']');

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


Page 1 of 1 (3 items)