开发者

jQuery click on span and travel

开发者 https://www.devze.com 2023-01-15 06:16 出处:网络
<span class=\"link\">move your body</span> How to make this span a link, without adding any inline javascript and extra attributes?
<span class="link">move your body</span>

How to make this span a link, without adding any inline javascript and extra attributes?

Also without transformation to <a>.

Like this:

$(".link").click(function(){
    // go to the http://开发者_如何学Pythonsite.com
})

Thanks.


You mean this:

$("span.link").click(function(){
   $(this).css('cursor', 'pointer');
   window.location = 'www.example.com';
})


$(".link").click(function(){
    window.location = "http://example.com";
})

Also it would be a nice touch to add

.link { cursor: pointer; } 


$(".link").click(function(){
    window.location = "http://yoururl.com"
})


$(".link").click(function(){
    $(location).attr('href', $(this).text());
})
0

精彩评论

暂无评论...
验证码 换一张
取 消