How can I get textarea element? I can"t use document.getElementById("textid") for it

I"m doing it lượt thích this now:

var note = document.getElementById("note");var notetext = note.querySelector("#textid");but it doesn"t work in IE(8)

How else I can vày it? jQuery is ok



If jQuery is okay, you can use find(). It"s basically equivalent lớn the way you are doing it right now.

Bạn đang xem: Jquery

$("#note").find("#textid");You can also use jQuery selectors lớn basically achieve the same thing:

$("#note #textid");Using these methods to lớn get something that already has an ID is kind of strange, but I"m supplying these assuming it"s not really how you plan on using it.

On a side note, you should know ID"s should be quality in your webpage. If you plan on having multiple elements with the same "ID" consider using a specific class name.

Update 2020.03.10

It"s a breeze khổng lồ use native sầu JS for this:

document.querySelector("#note #textid");If you want khổng lồ first find #note then #textid you have sầu khổng lồ kiểm tra the first querySelector result. If it fails to lớn match, chaining is no longer possible :(

var parent = document.querySelector("#note");var child = parent ? parent.querySelector("#textid") : null;
Improve this answer
edited Mar 10 "đôi mươi at 15:45
answered Atruyền thông quảng cáo 25 "11 at 22:35


9,64622 gold badges2828 silver badges5151 bronze badges
Is this answer outdated?
Yes | No
Add a bình luận |
Here is a pure JavaScript solution (without jQuery)

var _Utils = function (){ this.findChildById = function (element, childID, isSearchInnerDescendant) // isSearchInnerDescendant Example of use:

var myDiv = document.createElement("div");myDiv.innerHTML = "

" + "" + "" + "" + "
" + "
" + "
" + "
";var divToSearch = Utils.findChildById(myDiv, "divIdToSearch", true);
Improve sầu this answer
edited Jan 15 "16 at 22:07

675k158158 gold badges12531253 silver badges13881388 bronze badges
answered Feb 24 "15 at 11:40

Gil EpshtainGil Epshtain
5,70855 gold badges4242 silver badges6767 bronze badges
Is this answer outdated?
Yes | No
Add a phản hồi |
(Dwell in atom)
Improve sầu this answer
answered Feb 1 "17 at 6:39

Ankit ParmarAnkit Parmar
55866 silver badges20trăng tròn bronze badges
Is this answer outdated?
Yes | No
Add a phản hồi |
Using jQuery

$("#note textarea");or just

Improve sầu this answer
answered Aquảng cáo 25 "11 at 22:32
4,8512323 silver badges3434 bronze badges
Is this answer outdated?
Yes | No
Add a comment |
$(selectedDOM).find();function looking for all dom objects inside the selected DOM.i.e.

Paragraph 1

Paragraph 2


Paragraph 3

here if you write;

$("#mainDiv").find("p");you will get tree p elements together. On the other side,

$("#mainDiv").children("p");Function searching in the just children DOMs of the selected DOM object. So, by this code you will get just paragraph 1 & paragraph 2. It is so beneficial khổng lồ prevent browser doing unnecessary progress.

Xem thêm: Vỏ Xe Vision

Improve this answer
answered Dec trăng tròn "15 at 5:17
3,08322 gold badges3535 silver badges3838 bronze badges
Is this answer outdated?
Yes | No
Add a phản hồi |

Your Answer

Thanks for contributing an answer to Stack Overflow!

Please be sure lớn answer the question. Provide details & nội dung your research!

But avoid

Asking for help, clarification, or responding lớn other answers.Making statements based on opinion; baông xã them up with references or personal experience.

To learn more, see our tips on writing great answers.

Xem thêm: sửa lỗi quạt laptop kêu to

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Facebook
Sign up using Thư điện tử & Password

Post as a guest

Email Required, but never shown

Post as a guest

Thư điện tử

Required, but never shown

Post Your Answer Disthẻ

By clicking “Post Your Answer”, you agree lớn our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged javascript jquery element or ask your own question.

The Overflow Blog
Featured on Meta
How vày JavaScript closures work?
How vì chưng I kiểm tra if an element is hidden in jQuery?
How bởi vì I remove a property from a JavaScript object?
How bởi you get a timestamp in JavaScript?
How vị I redirect khổng lồ another webpage?
How vì I include a JavaScript tệp tin in another JavaScript file?
What does “use strict” vày in JavaScript, and what is the reasoning behind it?
How to kiểm tra whether a string contains a substring in JavaScript?
How can I remove sầu a specific nhà cửa from an array?
How to return the response from an asynchronous call?
Hot Network Questions more hot questions

Question feed
Subscribe to lớn RSS
Question feed To subscribe lớn this RSS feed, copy và paste this URL into your RSS reader.

Stack Overflow
Staông chồng Exchange Network
site thiết kế / logo sản phẩm © 2021 Staông chồng Exchange Inc; user contributions licensed under cc by-sa. rev2021.5.28.39383

Staông xã Overflow works best with JavaScript enabled

Your privacy

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device và discthua information in accordance with our Cookie Policy.

Chuyên mục: