Reputation: 932
i got an object like this
var obj = $("#something");
alert(obj.html());
and inside obj.html()
I have:
text <a href='link\to\somewhere'> click here </a> text
The question is, how do I get the values link\to\somewhere
and click here
by using jQuery?
Upvotes: 1
Views: 4512
Reputation: 3583
Building on what you already have:
var obj = $("#something");
var html = obj.html();
You can then pass the html to jQuery if you want to access it:
var href = $(html).attr('href')
Upvotes: 1
Reputation: 11486
For finding href:
var href = obj.find("a").attr("href");
This is because href is an attribute of the <a>
tag and hence the jQuery method attr()
can be used.
Upvotes: 2
Reputation: 3501
for href :
href = obj.find("a").attr("href");
and for click here :
text = obj.find("a").text();
Upvotes: 1
Reputation: 10675
var href = obj.find("a").attr("href"), // "link\to\somewhere"
text = obj.find("a").text(); // "click here"
Upvotes: 4