最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

hide textbox control using javascript or jquery - Stack Overflow

programmeradmin5浏览0评论

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.

Please help me

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.

Please help me

Share Improve this question edited Sep 27, 2011 at 6:31 Rafay 31k5 gold badges70 silver badges104 bronze badges asked Sep 27, 2011 at 6:28 user959128user959128 9572 gold badges9 silver badges11 bronze badges 1
  • Notice the plurality in the method getElementsByName. That indicates we are being returned an array. Loop it or pull the first item from it. – Atticus Commented Sep 27, 2011 at 6:41
Add a ment  | 

4 Answers 4

Reset to default 3

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 es 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)

  1. 暂无评论