Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder The Noob Coder's Avatar
    Join Date
    Jul 2012
    Location
    The City that Never Sleeps
    Posts
    99
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question jQuery: Why can't I change this link's innerHTML?

    I am trying to change the innerHTML of any link that has a certain href. This is the link in the in HTML:
    Code:
    <a href="#ecwid:category=0&amp;mode=category&amp;offset=0&amp;sort=normal" onclick="javascript: return false;">Store</a>
    This is the simple jQuery I am trying to use on it. It works when in other scenarios but not here for some reason and I can't figure out why.

    Code:
    jQuery(document).ready(function() {
    	jQuery('a[href="www.convolutedconstruct.com/store#ecwid:category=0&amp;mode=category&amp;offset=0&amp;sort=normal"]').text("Gallery Shop");
    });
    I've also tried this without any luck:
    Code:
    jQuery(document).ready(function() {
    	jQuery('a[href="#ecwid:category=0&amp;mode=category&amp;offset=0&amp;sort=normal"]').text("Gallery Shop");
    });
    Can anyone help me out here?

    On the other hand, is there anyway to grab the element by it's innerHTML ("Store" in this case) instead of by its href?
    Last edited by The Noob Coder; 10-12-2012 at 05:01 PM.

  • #2
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    Anchor tags don't have innerHTML. They have textNodes.
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

  • #3
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,918
    Thanks
    6
    Thanked 1,040 Times in 1,013 Posts
    Quote Originally Posted by WolfShade View Post
    Anchor tags don't have innerHTML. They have textNodes.
    Well, actually that’s what .text() does. Noob Coder, can you confirm that the selector is actually selecting the element? I think it isn’t because I see href="#ecwid… and you are prepending the domain in the selector: jQuery('a[href="www.convolutedconstruct.com/store#ecwid…

    After all, I think it’s pretty risky to use such a specific selector with many query strings etc. I wouldn’t rely on it always looking like that.

  • #4
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts
    how about mathcing it against the links current text?

    Code:
    jQuery(document).ready(function() {
    
    jQuery("a:contains('Store')").text('Gallery Shop');
    });

  • #5
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    3,020
    Thanks
    56
    Thanked 566 Times in 563 Posts
    Quote Originally Posted by WolfShade View Post
    Anchor tags don't have innerHTML.
    in which browser?
    Code:
    <body>
    <a id="thelink" href="#">link text</a>
    <script>
    alert(document.getElementById("thelink").innerHTML);
    </script>
    </body>
    or if you prefer:
    Code:
    alert($('#thelink').html())
    Last edited by xelawho; 10-12-2012 at 03:33 AM.

  • #6
    New Coder The Noob Coder's Avatar
    Join Date
    Jul 2012
    Location
    The City that Never Sleeps
    Posts
    99
    Thanks
    1
    Thanked 0 Times in 0 Posts
    @VIPStephen

    I know it's not the best way, but the code is in someone else's app that I can't edit. If it was up to me, I definitely would've put a class or id to it, but I can't. Second, I tried both with and without prepending the site's url to the href check. Neither worked.

    @DanInMa

    Thanks, but it didn't work.

  • #7
    New Coder The Noob Coder's Avatar
    Join Date
    Jul 2012
    Location
    The City that Never Sleeps
    Posts
    99
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Got it! The problem was that the element I was interested in didn't load yet, by the time that the jQuery was being called.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •