开发者

jquery toggle link not working in internet explorer

in internet explorer i do get this when i click on a link with javascript and query:

[object Object]

the link is:

<a href="javascript:$('#bla').toggle();">

thanks!

edit: regarding the answers so far: i can not use the 开发者_运维技巧recommended jquery way because i am autogenerating the links with a server-side script (there are actually several thousands on the page).


I believe its because IE tries to follow the link to the object bla. A better why to do this would be to set the onclick of the anchor element to call a function.

<a href="javascript:void(0)" onclick="toggleElement();">

Or an even better way would be to add an event listener in javascript.


<a href="#" id="linkId">Link</a>

and script is

$('#linkId')click(function(){
   $('#bla').toggle();
});


this is the right way

<script type="text/javascript" src="jquery-latest.js"> </script>
<script type="text/javascript">
    jQuery(function(){  
            jQuery('a#linkId').click(function() {
                            jQuery('#bla').toggle();
           });
    });
</script>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜