A string contains entire value of a html.i need to get the value of href tag i.e. src value.please help me to solve.
var alltext="a href="images/BGL30NA-10.JPG" target="""
var str=allText;
A string contains entire value of a html.i need to get the value of href tag i.e. src value.please help me to solve.
var alltext="a href="images/BGL30NA-10.JPG" target="""
var str=allText;
if you using jQuery:
try this:
var href = $('a').attr('href')
but better if you have <a></a>
with something id
and then
var href = $('#youId').attr('href')
'a href="images/BGL30NA-10.JPG" target=""'.match(/href="(.*?)"/)[1]
try this regex .
hope this may help you.
try this, it will gives the value of href in javascript
, below work only if you assign id
attribute in your anchor tag <a href="images\images1.jpg" id="image1">
for only value of href
document.getElementById("image1").getAttribute("href");
here is Jsfiddle
if you want to get full path then use this:
for full path of href document.getElementById("aaa").href;
here is Jsfiddle
if you have any doubts, ask it in below comment. @sriram
Parse the string before and use appropriate DOM functions:
str = "hello, <b>my name is</b> jQuery.";
html = $.parseHTML( str );
# use $('a').attr('href') or any other selector here
The mandatory link to TONY THE PONY.