开发者

Dynamically changing href property not working on <a> tag

I changed <a href=""> property on the fly on click on radio button.开发者_Python百科 Now, when I click the a tag.. it is not working as expected.

$('.poll input:radio').each(function() {
   $(this).click(function() {   
       $("#bts_EmailOverlayLink").attr('href','http://qa.makinglifebetterv1.com/offers/doitallmomscontest/default.aspx');
   });      
});

Please help me out.


Your question is somewhat confusing, but hopefully this is what you meant to do. There is no reason to loop through the radio buttons, just do this (I tested it and it works for me):

$('.poll input:radio').click(function() {
   $('#bts_EmailOverlayLink').attr('href', 'http://qa.makinglifebetterv1.com/offers/doitallmomscontest/default.aspx');
});

EDIT

For those of you that arrive to this page and are using jQuery 1.7+, jQuery's new (and recommended) way of binding events to elements is to use the the .on function. Although the above will still work, internally it will be rewritten to use .on anyway.

$('.poll input:radio').on('click', function() {
   $('#bts_EmailOverlayLink').attr('href', 'http://qa.makinglifebetterv1.com/offers/doitallmomscontest/default.aspx');
});
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜