Is the css # <my-id> selector (presumably) 100% equivalent [id = <my-id>] in jQuery?
Some prerequisites: I have a site with a table displaying a list of entities. Using jQuery, I can click on a row in a table that will load some additional data about the selected object using AJAX. A new row is inserted into the table below the clicked row. This line contains more detailed information about the object and is not really a line, only in HTML expressions. It contains a whole bunch of data. When you click on another line, the displayed details line will be hidden and the data line for the newly clicked object will be shown (loaded using AJAX if it is not already loaded). There are no problems.
The details bar also has a selection field. After loading the string using Ajax, I want to bind the onchange event to the selection. I make the following jQuery selection:
$("tr.entity_details[data-entity-id=" + entityId + "] select#SelectedDropDownValue")
Problem:
This also works great, except in a special case (which I have not yet been able to fully identify). Sometimes he does not select an item select. I am using VS2010 to debug and enter these two elements into my window:
$("tr.entity_details[data-entity-id=" + entityId + "] select#SelectedDropDownValue").length
$("tr.entity_details[data-entity-id=" + entityId + "] select[id=SelectedDropDownValue]").length
In those cases when the first does not choose anything, the second does. This is really strange for me because I thought the two selectors are equivalent.
The situation when I can do this: I have two objects in my table.
- First I click on the bottom: no problem; then I click on the top: no problem.
- First I press the top one: no problem; then I click on the bottom: PROBLEM.
, . , , - , javascript, . , . , , - , , - .
EDIT:
. IE9 Chrome. ASP.NET MVC 3 jQuery 1.5.1. . Html Helper DropDownListFor. select #, . . . , , , .
, ID, $('#my-id'), jQuery document.getElementById(), , - . .
- , jQuery document.getElementById(). document.querySelectorAll(), - CSS-, jQuery API DOM Sizzle. Sizzle.
, CSS, ID , , , , , . . . , Sizzle , , . , , , , .
, $('[id=my-id]'), , , . " ( ), my-id"; , , id my-id. , jQuery CSS , .
, HTML, HTML , , , , undefined , . , , , , .