A few questions about the basics of JavaScript - $, "not a function"

Being completely self-taught without actually reading in JavaScript (this is my job now, believe it or not) is a few things that I accept but don't understand.

The first is the dollar sign.

I understand that it is a shortcut to document.getElementById(), but if I record $and document.getElementById()the console - only to $return a value. However, this value always function()should not be. Element? What gives?

The second problem that I have is what continues to appear in my code, and I try to change the code to fix it. This is the error "... is not a function."

For instance:

if ($.inArray($(div_id).val(), arr) >= 0);

Gives an error .val() is not a function. What for? And how can I use the value div_idto see if it is in the array?

+3
4

. JQuery (, , ), $ jquery. HTML . , $( "# foo" ) jquery, id foo. HTML DOM $( "# foo" ) [0] - .

, $.inArray?

+4

$ .

, $ , .

/ $ document.getElementById, script :

function $(id) { return document.getElementById(id); }
+2

$ document.getElementById - . $ , , ​​ jquery, $ .

.val id, , jquery. , javascript jQuery

0

Javascript, DOM $, ( ) DOM , jQuery, Prototype Mootools. , , , API jQuery ( $.inArray, . http://api.jquery.com/jQuery.inArray/, , $ aliases document.getElementById , jQuery CSS, ).

$, undefined, , , API HTML.

0

Source: https://habr.com/ru/post/1763417/


All Articles