Search code examples
javascriptjquerygetelementbyid

Alternative for document in document.getElementById('ID')


I am completely a beginner in java script. As i know, by using this line of code:

document.getElementById('ID').value

It looks in the entire PHP file to find the value of that id (it's a text input). Is there any alternative for the documents on that line of code that let me to search only in a class?

for example i have a class called number, so :

this.block = $("#number");

can i use something like that:

this.block.getElementById('ID').value;

Or there is any another line of code that give me the value of a text input? Thanks a lot


Solution

  • You can use

    $("#number").find("#id")
    

    to search descendants of #number.

    But if your class is number you should use $(".number") instead since that is the class selector.