Reputation: 3058
I am migrating an rails application from prototype to Jquery, i am seeing a syntax like
var subEl = $$("#items_grid_container")[0]
subEl.style.height = windowGridContainerEm + "em"
I know how to convert the second part to Jquery, but how do i convert
var subEl = $$("#items_grid_container")[0]
to its equivalent in Jquery.
I tried $("#items_grid_container")[0]
but it is not working, any help would be appreciated. Thanks.
Upvotes: 2
Views: 813
Reputation: 74738
In prototype $$
is used to get the collection through CSS selectors. That would be a comma separated strings. So, I would say it internally uses document.querySelectorAll("tag/id/class/attributes")
.
Although id selector returns only one element.
So, jQuery equivalent is just with single $
:
$("#item_grid_container")[0]
Will return you the DOM element instead of jQuery object. So, jQuery methods cannot be applied on DOM elements and vice versa. Only jQuery object can use the jQuery methods. If you need jQuery object then you don't have to add [0]
in the selector.
So you have to do this :
var el = $("#item_grid_container");
el.width(thevarwidth);
Upvotes: 2