Hai Truong IT
Hai Truong IT

Reputation: 4187

How to get link URL from JavaScript?

I have the following code :

<?php
$i = 0;
foreach($this->list as $l) { 
$link = JRoute::_("index.php?option=com_ecommerce&view=detail&id=$l->id");
<div class="quickview" id="quickview_<?php echo $i;?>">
<a href='<?php echo $link ?>' class='basic'>Quick view</a>
</div>
i++;
}
?>
<script>
jQuery(function ($){
    var link = $('.quickview .basic').val();
    $('.quickview .basic').click(function (e) {
    alert(link);
        return false;
    });
});
</script>

I can't get link from tag <a>.

Upvotes: 1

Views: 1447

Answers (2)

Johan Dettmar
Johan Dettmar

Reputation: 29476

If you refer

I can't get link from tag <a>, please help me!

to the link you're clicking, this would work:

$(".quickview").find(".basic").click(function(e) {

     e.preventDefault();
     var url = $(this).attr("href");
     alert(url);
});

Upvotes: 0

Py.
Py.

Reputation: 3599

var link =$('.quickview .basic').attr("href"); should do the trick.

Upvotes: 1

Related Questions