Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Execute shortcodes in excerpts

Tags:

jquery

I need a JQuery help..

i have populated checkboxes as follows

<span class="checked">
 <input class="cbid" type="checkbox" name="cb1">
</span>
<span >
  <input class="cbid" type="checkbox" name="cb2">
</span>
<span class="checked">
  <input class="cbid" type="checkbox" name="cb3">
</span>

i need to make an array using the value of name attribute of checkboxes where their parent's(span) class is 'checked'

e.g.

["cb1","cb3"]

Thanks

like image 357
Mark Timothy Avatar asked Jun 07 '26 12:06

Mark Timothy


1 Answers

var names = $('.checked > :checkbox').map(function() {
    return this.name;
}).toArray();

Fiddle

Using a class selector in conjunction with the child selector (>) and the jQuery (Sizzle) :checkbox selector (which is equivalent to [type=checkbox]).

$().map() returns a jQuery object, hence the .toArray() at the end. This is just one of the many ways to achieve the requested result.

like image 198
Fabrício Matté Avatar answered Jun 10 '26 02:06

Fabrício Matté



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!