Reputation: 207
I have this link...
<a class="class sub1 class2" href="test.asp?Code=2D3824&ID=1">
I need to get the ID value in the href. I tried:
jQuery("a.class.sub1.class2[href$='2D3824']").text();
To try and get a string to break up, but it comes back empty. Any ideas?
Upvotes: 0
Views: 62
Reputation: 318202
If the string always has the same format :
jQuery("a.class.sub1.class2[href*='2D3824']").attr('href').split('=')[2];
To get the value based on the querystring key with a regex:
jQuery("a.class.sub1.class2[href*='2D3824']").attr('href').match(/\&ID\=(.*?)$/)[1];
Upvotes: 1
Reputation: 4616
You need to get the property for the href, not the text of the anchor, and you also need to use the contains selector, *=.
jQuery("a.class.sub1.class2[href*='2D3824']").prop('href').split('=')[2];
Upvotes: 0