Extract Url From Html Using Javascript And Use It In A Function
I need to extract URL link from html. There is only one such link on the whole page. Then I need to add use it as a.href in this fun
Solution 1:
Try this:
functionchangespan() {
var spans = document.querySelectorAll('span.image'),
href = document.querySelector('.nofollow-link').href;
for (var i = spans.length; i--; ) {
var a = document.createElement('a');
a.href = href;
spans[i].appendChild(a).appendChild(a.previousSibling);
}
}
but change you link class to something else then 1
it can't start with number:
<arel="nofollow"href="link"class="nofollow-link">Link</a>
Solution 2:
document.getElementsByTagName("a")[0].getAttribute("href");
Solution 3:
functionchangespan() {
var spans = document.querySelectorAll('span.image');
for (var i = spans.length; i--; ) {
var a = document.createElement('a');
a.href = $(".1").attr('href');
spans[i].appendChild(a).appendChild(a.previousSibling);
}
}
Post a Comment for "Extract Url From Html Using Javascript And Use It In A Function"