Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-11-2012, 09:54 PM   PM User | #1
The Noob Coder
New Coder

 
Join Date: Jul 2012
Posts: 72
Thanks: 1
Thanked 0 Times in 0 Posts
The Noob Coder is an unknown quantity at this point
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 04:01 PM..
The Noob Coder is offline   Reply With Quote
Old 10-11-2012, 10:10 PM   PM User | #2
WolfShade
Regular Coder

 
Join Date: Apr 2012
Location: St. Louis, MO, USA
Posts: 960
Thanks: 7
Thanked 100 Times in 100 Posts
WolfShade is an unknown quantity at this point
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".
WolfShade is offline   Reply With Quote
Old 10-11-2012, 10:27 PM   PM User | #3
VIPStephan
The fat guy next door


 
VIPStephan's Avatar
 
Join Date: Jan 2006
Location: Halle (Saale), Germany
Posts: 7,697
Thanks: 5
Thanked 875 Times in 850 Posts
VIPStephan is a jewel in the roughVIPStephan is a jewel in the roughVIPStephan is a jewel in the rough
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.
__________________
Don’t click this link!
VIPStephan is offline   Reply With Quote
Old 10-12-2012, 01:32 AM   PM User | #4
DanInMa
Senior Coder

 
DanInMa's Avatar
 
Join Date: Nov 2010
Location: Salem,Ma
Posts: 1,335
Thanks: 13
Thanked 207 Times in 207 Posts
DanInMa is on a distinguished road
how about mathcing it against the links current text?

Code:
jQuery(document).ready(function() {

jQuery("a:contains('Store')").text('Gallery Shop');
});
__________________
- Firebug is a web developers best friend! - Learn it, Love it, use it!
- Validate your code! - JQ/JS troubleshooting
- Using jQuery with Other Libraries - Jslint for Jquery/other JS library users
DanInMa is offline   Reply With Quote
Old 10-12-2012, 02:30 AM   PM User | #5
xelawho
Senior Coder

 
xelawho's Avatar
 
Join Date: Nov 2010
Posts: 2,461
Thanks: 52
Thanked 457 Times in 455 Posts
xelawho will become famous soon enoughxelawho will become famous soon enough
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 02:33 AM..
xelawho is offline   Reply With Quote
Old 10-12-2012, 03:40 PM   PM User | #6
The Noob Coder
New Coder

 
Join Date: Jul 2012
Posts: 72
Thanks: 1
Thanked 0 Times in 0 Posts
The Noob Coder is an unknown quantity at this point
@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.
The Noob Coder is offline   Reply With Quote
Old 10-12-2012, 03:51 PM   PM User | #7
The Noob Coder
New Coder

 
Join Date: Jul 2012
Posts: 72
Thanks: 1
Thanked 0 Times in 0 Posts
The Noob Coder is an unknown quantity at this point
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.
The Noob Coder is offline   Reply With Quote
Reply

Bookmarks

Tags
jquery, links, text

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:43 AM.


Advertisement
Log in to turn off these ads.