开发者

getByElementId hide?

document.getElementById(id).hide("slide", { direction: "down" }, 1000);

This is in my javascript file.

I'm trying to hide a div, which has the id of var 'id'.

The error console is listing that it is开发者_StackOverflown't a function.

Edit:

I don't think I'm getting the right element this way (using $("#" + id)).

Let's say im making the div like this: <div id="2">, and the javascript function is getting 2


document.getElementById(id) is Dom element. and it has no function hide

You have to use $('#'+id).hide. Or $(document.getElementById(id)).hide


$("#" + id).hide(...);

Don't use getElementById if you have jQuery.

Also, to fix your initial code, here's how it should have looked like:

$(document.getElementById(id)).hide(...);

This is because jQuery doesn't extend DOM elements, but it can "convert" them into jQuery elements (which have those cute functions) with $().


When using document.getElementById(..) you cannot use jQuery functions like hide(..). Use the jQuery shorthand - $("#" + id)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜