Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
79
rated 0 times [  85] [ 6]  / answers: 1 / hits: 17771  / 7 Years ago, fri, june 23, 2017, 12:00:00

This is my Javascript code:



$(.woocommerce-LoopProduct-link).each(function(){
var str=$(this).attr(src);
console.log(str);
});


What I want to see is a string that contain http://mywebsitelinked.com for example.



Now what the console display is:



a.woocommerce-LoopProduct-link
accessKey:


And all the other thing contained in a.wooocommerce-LoopProduct-link


More From » jquery

 Answers
11

Instead of this:



$(this).attr(src);


try



$(this).attr(href);


as you are trying to get the URL and URL is in the href attribute of the anchor.



Ex:





$(document).ready(function(){
alert($('a').attr('href'));
});

<script src=https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js></script>


<a href=http://google.com/>Google></a>




[#57330] Wednesday, June 21, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
bryonk

Total Points: 161
Total Questions: 116
Total Answers: 107

Location: Albania
Member since Sun, Nov 22, 2020
4 Years ago
bryonk questions
;