开发者

Why won't this DOM element disappear?

开发者 https://www.devze.com 2022-12-22 15:56 出处:网络
I have a page that uses jQuery with a small glitch. I managed to get this down to a simple example that demonstrates the problem:

I have a page that uses jQuery with a small glitch.

I managed to get this down to a simple example that demonstrates the problem:

<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">

function hideIt()
{
    $('#hideme').fadeOut('slow', function() { $(this).remove(); } );
}

</script>
</head>
<body>
<div id='#hideme'>Hide me!</div>
<button onclick='hideIt();'>Hide</button>
</body>
</html>

As you would expect, the problem is simple: the caption doesn't disappear.

What simple thing开发者_如何学Go did I overlook? (Or if it's not a simple thing, what complicated thing did I miss?)


Try removing the # in <div id='#hideme'>Hide me!</div> :)


The selector is not finding your div, because you have an # character on it:

Change:

<div id='#hideme'>Hide me!</div>

To:

<div id='hideme'>Hide me!</div>


The ID of the div should be "hideme" not "#hideme"

0

精彩评论

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