1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How can i select the a href text inside h1 tag in jQuery?

Discussion in 'jQuery' started by joyceismyname, May 31, 2012.

  1. #1
    Hello,

    I need help selecting an a href text inside h1 tag.

    Here is what it looks like

    <h1><a href="#"> the is not to be selected</a> and <a href="#">this should be selected</a></h1>
    <p>please select only the <a href="#">text</a> inside the header a href</p>
    <h1><a href="#"> the is not to be selected</a> and <a href="#">this should be selected again</a></h1>
    <p>please select only the <a href="#">text</a> inside the header a href</p>

    $(document).ready(function(){

    $(":header").each(function(){
    $("a").each(function(){
    $entry = $(this).text();

    alert($entry);
    });
    });
    });

    that code above is not working.

    Any help is highly appreciated. Thanks
     
    joyceismyname, May 31, 2012 IP
  2. smbat.yeranyan

    smbat.yeranyan Greenhorn

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    21
    #2
    you can use $("h1").attr("href");
     
    smbat.yeranyan, Jul 11, 2012 IP
  3. kravits88

    kravits88 Peon

    Messages:
    28
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    ^^ Yep. Do that
     
    kravits88, Aug 18, 2012 IP
  4. hassanahmad2

    hassanahmad2 Active Member

    Messages:
    243
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    60
    #4
    
    $(document).ready(function() {
    
    	$("h1 a").each(function() {
    		$entry = $(this).attr("href");
    		alert($entry);
    	});
    
    });
    
    Code (markup):
     
    hassanahmad2, Sep 1, 2012 IP