Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery filter .not()

I have a form with image thumbnails to select with checkboxes for downloading. I want an array with the images in jQuery for an Ajax call.

2 questions:
- On the top of the table there is a checkbox to toggle all checkboxes that I want to exclude from the mapping. I had a look at jQuery's .not() but I can't implement it with the :checkbox selector
- is the following example code correct?

$(document).ready(function() {
    $('#myform').submit(function() {
        var images = $("input:checkbox", this).map(function() {
            return $(this).attr("name");
        }).get().join();

        alert(images); // outputs: ",check1,check2,check3"
        return false; // cancel submit action by returning false
    });
}); // end doc ready

HTML:

    <form id="myform" action="" >
    <input type="checkbox" id="toggleCheck" onclick="toggleSelectAll()" checked="checked" ><br />

    <input type="checkbox" name="001.jpg" checked="checked" /><br />
    <input type="checkbox" name="002.jpg" checked="checked" /><br />
    <input type="checkbox" name="003.jpg" checked="checked" /><br />
    <br />
    <input type="submit" value="download" >
</form>
like image 650
FFish Avatar asked Apr 18 '10 14:04

FFish


People also ask

What is not () in jQuery?

The not() method returns elements that do not match a certain criteria. This method lets you specify a criteria. Elements that do not match the criteria are returned from the selection, and those that match will be removed. This method is often used to remove one or more elements from a group of selected elements.

What is not method?

not() method constructs a new jQuery object from a subset of the matching elements. The supplied selector is tested against each element; the elements that don't match the selector will be included in the result.

How do I select all divs except one?

We can very easily achieve this using the :not and :first-child selectors in a combination. For example, if you want to select all paragraphs except the first one that are inside a div element, you can use div :not(:first-child) selector.

Can we use multiple selectors in jQuery?

You can specify any number of selectors to combine into a single result. This multiple expression combinator is an efficient way to select disparate elements. The order of the DOM elements in the returned jQuery object may not be identical, as they will be in document order.


1 Answers

You can exclude it via the ID, like this:

$("input:checkbox", this).not("#toggleCheck").map(....

This would exclude the select all toggle from the mapping.

like image 179
Nick Craver Avatar answered Oct 13 '22 19:10

Nick Craver