Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I've been looking over the <a href="http://docs.jquery.com/" rel="noreferrer">jQuery docs</a> and I think we can do this in one line using <a href="http://docs.jquery.com/Selectors" rel="noreferrer">selectors</a>:</p> <pre><code>$("#myForm :input[value!='']").serialize() // does the job! </code></pre> <p>Obviously #myForm gets the element with id "myForm" but what was less obvious to me at first was that the <strong>space character</strong> is needed between #myForm and :input as it is the <a href="http://docs.jquery.com/Selectors/descendant" rel="noreferrer">descendant</a> operator.</p> <p><a href="http://docs.jquery.com/Selectors/input" rel="noreferrer"><strong>:input</strong></a> matches all input, textarea, select and button elements.</p> <p><a href="http://docs.jquery.com/Selectors/attributeNotEqual" rel="noreferrer"><strong>[value!='']</strong></a> is an attribute not equal filter. The weird (and helpful) thing is that <strong>all :input</strong> element types have value attributes even selects and checkboxes etc.</p> <p>Finally to also remove inputs where the value was '.' (as mentioned in the question):</p> <pre><code>$("#myForm :input[value!=''][value!='.']").serialize() </code></pre> <p>In this case juxtaposition, ie <a href="http://docs.jquery.com/Selectors/attributeMultiple" rel="noreferrer">placing two attribute selectors next to each other</a>, implies an AND. <a href="http://docs.jquery.com/Selectors/multiple" rel="noreferrer">Using a comma</a> implies an OR. Sorry if that's obvious to CSS people!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload