In my home page I have links in a pattern.
The URLs have portfolio-item
in the href.
Ex:
For now I have to find if a URL has the word portfolio-item
or not.
If portfolio-item
is found then I have to relace the href to #
What I mean is:
If the anchor tag is <a href="www.mysite.com/portfolio-item/whatEver">What Ever</a>
what ever I have to change it to <a href="#">what ever</a>
Because the above HREF has the word portfolio-item
.
How can I check the all the anchor tags which are in page and check for the word portfolio-item
and if it is found then replace the href value to #
using jQuery?
Use attribute contains selector
$('a[href*="portfolio-item"]').attr('href', '#');
The selector a[href*="portfolio-item"]
will select all the <a>
elements whose href
attribute value contains the string portfolio-item
anywhere.