IDs must be unique in your document, meaning that you shouldn’t do this:
<input type="checkbox" name="chk[]" id="chk[]" value="Apples" /> <input type="checkbox" name="chk[]" id="chk[]" value="Bananas" />
Instead, drop the ID, and then select them by name, or by a containing element:
<fieldset id="checkArray"> <input type="checkbox" name="chk[]" value="Apples" /> <input type="checkbox" name="chk[]" value="Bananas" /> </fieldset>
And now the jQuery:
var atLeastOneIsChecked = $('#checkArray:checkbox:checked').length > 0; //there should be no space between identifier and selector // or, without the container: var atLeastOneIsChecked = $('input[name="chk[]"]:checked').length > 0;
Related Posts:
- How do I check whether a checkbox is checked in jQuery?
- How do I check whether a checkbox is checked in jQuery?
- Check if checkbox is checked with jQuery
- How do I check whether a checkbox is checked in jQuery?
- How to properly use jsPDF library
- ReferenceError: $ is not defined
- jQuery document.createElement equivalent?
- Pure JavaScript equivalent of jQuery’s $.ready() – how to call a function when the page/DOM is ready for it [duplicate]
- How can I scroll to an element using jQuery?
- jQuery.click() vs onClick
- jQuery Get Selected Option From Dropdown
- How to add jQuery code into HTML Page
- How can I get the data-id attribute?
- Setting “checked” for a checkbox with jQuery
- Bootstrap Dropdown menu is not working
- jquery SlideToggle effect in upward direction?
- Change Background color (css property) using Jquery
- Failed to load resource: net::ERR_FILE_NOT_FOUND loading json.js
- Get class name using jQuery
- Export html table data to Excel using JavaScript / JQuery is not working properly in chrome browser
- Set timeout for ajax (jQuery)
- Use images like checkboxes
- How to read xml file contents in jQuery and display in html elements?
- Jquery swipe left or right on mobile
- How to move an element into another element?
- How to check all checkboxes using jQuery?
- Create table with jQuery – append
- How to convert selected HTML to Json?
- How to Open New window on every Click
- Uncaught TypeError: Cannot read property ‘top’ of undefined
- How can I select an element by name with jQuery?
- jQuery disable/enable submit button
- Play an audio file using jQuery when a button is clicked
- How to move an element after another element using JS or jquery?
- Why is the jquery script not working?
- document.getElementsByClassName().innerHTML always returns “undefined”
- Jquery button click() function is not working
- HTML text input allow only numeric input
- Refresh/reload the content in Div using jquery/ajax
- Print the contents of a DIV
- Embedding instagram webpage inside an iframe
- How to get height of div in px dimension
- Set value to currency in
- jQuery: Uncaught Error: Syntax error, unrecognized expression
- Creating a div element in jQuery
- SyntaxError: JSON.parse: unexpected end of data at line 1 column 1 of the JSON data
- How to use in jQuery :not and hasClass() to get a specific element without a class
- HTML Entity Decode
- How to display raw JSON data on a HTML page
- Clearing my form inputs after submission
- Get class list for element with jQuery
- Reload an iframe with jQuery
- How to scroll an HTML page to a given anchor
- Highlight a word with jQuery
- jQuery checkbox change and click event
- How do I refresh a DIV content?
- How to implement “select all” check box in HTML?
- Why is jquery show() not working in example
- How can I use jQuery to run MySQL queries?
- jQuery sort elements using data id
- jQuery scrollTop() method not working
- FormData append not working
- getContext is not a function
- How to change the text of a label?
- Print a div content using Jquery
- Get the size of the screen, current web page and browser window
- Using “×” word in html changes to ×
- Closing Bootstrap modal onclick
- Fire oninput event with jQuery
- Fully responsive HTML5 video
- Changing the selected option of an HTML Select element
- HTML anchor link – href and onclick both?
- How can I know which radio button is selected via jQuery?
- How to scroll to top of page with JavaScript/jQuery?
- How to use aria-expanded=”true” to change a css property
- How to set “style=display:none;” using jQuery’s attr method?
- Adding JavaScript to a WordPress website
- Putting custom html/js page into Elementor as it’s own block
- internal anchor links no longer working after upgrade
- How to run Javascript popup modal in a loop?
- Can’t Listen to KeyDown in TInyMCE Iframe (jQuery) and Pass it to Parent HTML FORM
- Styling parent based on a child element of a child in a WordPress page
- Can I use complex HTML with Twitter Bootstrap’s Tooltip?
- How do I redirect to another webpage?
- Infinite Scrolling in Asp.Net MVC with jQuery / AJAX Issues
- What are the difference between $(document).bind(‘ready’, function) and $(document).ready(function() {})
- How can I print using JQuery
- Dynamically load JS inside JS
- How to open a URL in a new Tab using JavaScript or jQuery?
- HTML make text clickable without making it a hyperlink
- Getting HTML form values
- How to fix javascript .toFixed is not a Function error
- jQuery checkbox checked state changed event
- Javascript, viewing [object HTMLInputElement]
- Why onbeforeunload event is not firing
- etect the Enter key in a text input field
- Contact Form 7 – Give each checkbox a class?
- How to set callback to execute after all the tinyMCE editors have been initialized?
- Use one javascript variable into another javascript file