Reputation: 12512
I need to be able to detect if a target string is a link or not. If yes, i need to grab the URL and place it into a var, do something with the string a (run through a plugin to truncate), and then wrap new string into the link again. I think i should be able to accomplish this with jQuery, right?
<div class="item">some string</div>
<div class="item">another string</div>
<div class="item"><a href="myUrl.php">linked string</a></div>
Upvotes: 0
Views: 81
Reputation: 10258
I think this should work for you it will find all links in the class off item
$(".item a").each(function(index){
var url = $(this).attr("href");
url = url+"hello";
$(this).attr("href", url);
});
Example http://jsfiddle.net/gcLU4/
Upvotes: 0
Reputation: 17573
I guess you want something like:
$('.item > a').each(function(){
var url = this.href;
//do your stuff
});
Upvotes: 3