How do you get the id's in a div?
<div id="container">
<div id="frag-123">ass</div>
<div id="frag-123">ass</div>
<div id="frag-123">ass</div>
</div>
Thanks!
How do you get the id's in a div?
<div id="container">
<div id="frag-123">ass</div>
<div id="frag-123">ass</div>
<div id="frag-123">ass</div>
</div>
Thanks!
$('div', $('div#container')).each(function() {
console.log($(this).attr('id'));
});
There are multiple ways to do this. You can use map()
:
var ids = $("#container").children().map(function(n, i) {
return n.id;
});
or each()
:
$("#container").children().each(function(n, i) {
var id = this.id;
// do something with it
});
etc
to get them as an array of strings
var ids = $.map($('#container div'), function(n,i) {
return n.id
});
i'm trying to pass it to my webmethod as a string[] array. But im having trouble with it.
var ids = $.map($("#container-1").children(), function(n, i) {
return n.id;
});
$.ajax({
type: 'POST',
url: 'Loader.asmx/Active',
data: "{'tab':'" + ids + "'}",
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function(msg) {
}
});