开发者

hide textbox control using javascript or jquery

I want to hide textbox control using javascript or jquery.I have used javascript

document.getElementsByName('Custom_Field_Custom1').style.display="none";

java console shows me this error :

document.getElementsByName('Custom_Field_Custom1').style.display="none" is undefined.

Plea开发者_Python百科se help me


getElementsByName returns an array. You either want to use an ID and call getElementById, or use getElementsByName('Custom_Field_Custom1')[0].


getElementsByName returns a NodeList not an HTMLElementNode. It doesn't have a style property, so you get the error because undefined.display isn't allowed.

Loop over the NodeList as if it was an array.


$('input:text') would select all textboxes in the page.

Hence, $('input:text').hide(); would hide all your textboxes.

If you need to hide a single textbox you can give it an id, as in <input type="text" id="Custom_Field_Custom1" />

$('#Custom_Field_Custom1').hide(); would then hide that single one.


Well seems all the possible answer comes here. I just simplified the answer :

for change CSS with jquery use following code :

$('#Custom_Field_Custom1').css('display','none');

For hide the text box with jquery use following code :

$('#Custom_Field_Custom1').hide();

In both case remember one thing here "Custom_Field_Custom1" must be id of the textbox.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜