Underlining in Javascript?

邮差的信 提交于 2019-12-02 04:31:13

you can do this by

 onMouseOver="this.style.textDecoration='none';"

Here's your answer:

<a onmouseover="this.style.textDecoration='none';"  onmouseout="this.style.textDecoration='underline';">hover me</a>


if you're able to use jQuery it would be easier. Just write once the following code. You haven't to change your markup then.

<script type="text/javascript">
(function($) {
    $( function() {
        $('a').hover(
            function() {
                $(this).css('text-decoration','none');
            },
            function() {
                $(this).css('text-decoration','underline');
            }
        )
    } );
} (jQuery));
</script>

I think you shouldn't use javascript, but CSS:

.underlineHover:hover {
    text-decoration: underline;
}
<span class="underlineHover">Content</span>

Note: I used the class underlineHover, but be aware that classes should have a semantic meaning instead of styling one.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!