Hello Im relative new into JQuery... more used to PHP Its just really simple I think but Im too stupid and if im honest JS cracks my mind....(in OOP Ive to learn much too...)
So I already found out that there arent arrays like in PHP.
Ok lets start.
My HTML Looks like this:
<div id="content">
<ul id="ul_1"></ul>
<ul id="ul_2"></ul>
<ul id="ul_3"></ul>
</div>
And now I want to generate this out of that anyway
controller = {
"#ul_1": 1,
"#ul_2": 1,
"#ul_3": 1
};
So to be more precise, at moment its hard coded like the code example above this line. But I want that it generates automatically out of the HTML or better DOM.
I already tried .map
, .find
and .each
... but im too disabled.
I always prefered it make it at once, so I mean no iteration with .each
if that would be possible. I think maybe its possible to create a new object out of the $.('#content')
object but in the style I need it.
Thank very much you Rycochet
heres the solution for my case
var controller = {};
$("#content > ul").each(function (i, el) {
controller['#' + $(el).attr('id')] = 1;
});
Is there another solution, too? Like with .map or is that the best, fastest and easiest way to do it?