0

I have this hyperlink in anchor tag

<a href="/index.php?var1=rule-power" > Text </a>

Now i want that when that page is clicked i have the page with hyperlinks like

<a href="" >rule-power </a>

Is it possible that i can grab the var1 using jquery . even if its partial match it willl be good and then remove that tag

something like

NewVar =getParameter(var1);
$.find(a).withtext(NewVar).hide()

1 Answers1

2

You can use Artem Barger's answer here to get the querystring variable, then you can use :contains() to do a partial match, like this:

var var1 = getParameterByName('var1'); //from linked answer
$('a:contains("' + var1 + '")').hide();

Or, if you wanted an exact match, use .filter() and .text(), like this:

var var1 = getParameterByName('var1');
$('a').filter(function() { 
  return $(this).text() == var1;
}).hide();
Community
  • 1
  • 1
Nick Craver
  • 623,446
  • 136
  • 1,297
  • 1,155
  • Much better (retracting answer) nice job. – Dr. Frankenstein Jun 21 '10 at 00:47
  • +1 - Although I can't tell if OP wants to `.hide()` the tag (seems apparent from the code example) or "hide" the path in the `href` (seems apparent from the HTML). I have a feeling it is the latter if these are nav links. – user113716 Jun 21 '10 at 00:50
  • @patrick - I *think* he wants to hide the tag, e.g. wants to hide the link that goes to the current page in the menu...I would disable it, turn it black, etc, but whatever the OP is after works. – Nick Craver Jun 21 '10 at 00:56
  • thanks for that , actually i wanted to something else but that would take tto much time to write so i just use hide. The basic thing was it just wanted the element . thanks guys –  Jun 21 '10 at 01:00