Undocumented behavior in jQuery?

Is the following behavior documented (i.e. should I rely on it)?

Due to an error, I got a dialog box and referred to its identifier using one word in javascript. Surprisingly, I did not get the error, and the code worked as intended

The example (on JSFiddle.net here ) has 2 simple dialog boxes

<div id="Hello">
   <input id="box1" name="box1" type="text" value="not change">
</div>
<div id="Goodbye">
   <input id="box1" name="box1" type="text" value="not change">
</div>

And javascript that lacks a string Hello = $("#Hello");.

$("#Hello").dialog({
    autoOpen:false, 
    modal:true, 
    width:"auto"}
);
$("#Hello").dialog("open");
$("#Goodbye").dialog("open");
$('[name="box1"]',Hello).val("test");  

Surprisingly, the last line updates the text box in the div Hello, but I can not find anywhere where this behavior is documented. Is this just an obscure side effect you can't rely on, or is it a valid jQuery selector style?

FYI, I am using Chrome Version 32.0.1700.107 m.

+4
4

, . "Hello", , , :

window.Hello = document.getElementById("Hello");

, , . jQuery .

http://jsfiddle.net/w4YJw/

, , , . , , id="submit" form.submit()

+4

$('[name="box1"]',Hello) DOM , name box1, . , undefined, jQuery document.

, .

+1

The jQuery constructor should work, you just went in undefinedfor context, it can still find an element named "box1" in the document area.

0
source

Try this in the same script example:

$(text).val("test");

It puts the value of the input field because it finds it in the attributes and matches it

-1
source

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


All Articles