How do I toggle an element’s class in pure JavaScript?

2014 answer: classList.toggle() is the standard and supported by most browsers. Older browsers can use use classlist.js for classList.toggle(): var menu = document.querySelector(‘.menu’) // Using a class instead, see note below. menu.classList.toggle(‘hidden-phone’); As an aside, you shouldn’t be using IDs (they leak globals into the JS window object).

Toggle input disabled attribute using jQuery

$(‘#el’).prop(‘disabled’, (i, v) => !v); The .prop() method accepts two arguments: Property name (disabled, checked, selected) anything that is either true or false Property value, can be: (empty) – returns the current value. boolean (true/false) – sets the property value. function – Is executed for each found element, the returned value is used to set … Read more

Toggle Checkboxes on/off

You can write: $(document).ready(function() { $(“#select-all-teammembers”).click(function() { var checkBoxes = $(“input[name=recipients\\[\\]]”); checkBoxes.prop(“checked”, !checkBoxes.prop(“checked”)); }); }); Before jQuery 1.6, when we only had attr() and not prop(), we used to write: checkBoxes.attr(“checked”, !checkBoxes.attr(“checked”)); But prop() has better semantics than attr() when applied to “boolean” HTML attributes, so it is usually preferred in this situation.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)