toggle

Button text toggle in jquery

拈花ヽ惹草 提交于 2019-11-26 19:44:56
When i click ".pushme" button, it turns its text to "Don't push me". I want to turn the text again to "push me" when button is clicked again. How can i do that? <html> <head> <script src="http://code.jquery.com/jquery-latest.js"></script> </head> <body> <button class='pushme'>PUSH ME</button> <script> $(".pushme").click(function () { $(this).text("DON'T PUSH ME"); }); </script> </body> </html> http://jsfiddle.net/DQK4v/ Thanks. You can use text method: $(function(){ $(".pushme").click(function () { $(this).text(function(i, text){ return text === "PUSH ME" ? "DON'T PUSH ME" : "PUSH ME"; }) });

Sliding divs horizontally with JQuery

柔情痞子 提交于 2019-11-26 16:08:33
问题 so I'm very new to Javascript and Jquery. What I'd like to create is a two column page where links on the left column will cause a div on the right to slide in horizontally from left to right, and slide out of view when clicked again. I know I need to use slide toggle effect but I'm having trouble implementing it in a way that each individual link causes a different div to slide... I've attempted to tweak a few jsfiddles I've found via google searches but I'm pretty lost when it comes to

Click toggle with jQuery

别等时光非礼了梦想. 提交于 2019-11-26 15:10:36
问题 I've used a hover function where you do x on mouseover and y and mouseout. I'm trying the same for click but it doesn't seem to work: $('.offer').click(function(){ $(this).find(':checkbox').attr('checked', true ); },function(){ $(this).find(':checkbox').attr('checked', false ); }); I want the checkbox to be checked when clicking on a div , and unchecked if clicked again - a click toggle. 回答1: This is easily done by flipping the current 'checked' state of the checkbox upon each click. Examples

How do I toggle an element&#39;s class in pure JavaScript?

家住魔仙堡 提交于 2019-11-26 14:21:10
I'm looking for a way to convert this jQuery code (which is used in responsive menu section) to pure JavaScript. If it's hard to implement it's OK to use other JavaScript frameworks. $('.btn-navbar').click(function() { $('.container-fluid:first').toggleClass('menu-hidden'); $('#menu').toggleClass('hidden-phone'); if (typeof masonryGallery != 'undefined') masonryGallery(); }); 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

Toggle visibility property of div

扶醉桌前 提交于 2019-11-26 14:18:44
问题 I have an HTML 5 video in a div. I then have a custom play button - that works fine. And I have the video's visibility set to hidden on load and visible when the play button is clicked, how do I return it to hidden when the play button is clicked again? function showVid() { document.getElementById('video-over').style.visibility = 'visible'; } #video-over { visibility: hidden; background-color: rgba(0, 0, 0, .7) } <div id="video-over"> <video class="home-banner" id="video" controls=""> <source

Toggle input disabled attribute using jQuery

我与影子孤独终老i 提交于 2019-11-26 14:08:09
Here is my code: $("#product1 :checkbox").click(function(){ $(this) .closest('tr') // Find the parent row. .find(":input[type='text']") // Find text elements in that row. .attr('disabled',false).toggleClass('disabled') // Enable them. .end() // Go back to the row. .siblings() // Get its siblings .find(":input[type='text']") // Find text elements in those rows. .attr('disabled',true).removeClass('disabled'); // Disable them. }); How do I toggle .attr('disabled',false); ? I can't seem to find it on Google. $('#el').prop('disabled', function(i, v) { return !v; }); The .prop() method accepts two

Jquery, hide & show list items after nth item

别来无恙 提交于 2019-11-26 13:46:57
问题 Say I have an unordered list, like so: <ul> <li>One</li> <li>Two</li> <li>Three</li> <li>Four</li> <li>Five</li> </ul> How would I, using JQuery, hide the last 2 list items and have a 'show more' link there, so when clicked upon, the last 2 list items would appear? <ul> <li>One</li> <li>Two</li> <li>Three</li> <li style="display:none;">Four</li> <li style="display:none;">Five</li> <li>Show More</li> </ul> 回答1: Try the following code example: $('ul li:gt(3)').hide(); $('.show_button').click

Toggle Checkboxes on/off

若如初见. 提交于 2019-11-26 12:00:42
I have the following: $(document).ready(function() { $("#select-all-teammembers").click(function() { $("input[name=recipients\\[\\]]").attr('checked', true); }); }); I'd like the id="select-all-teammembers" when clicked to toggle between checked and unchecked. Ideas? that aren't dozens of lines of code? 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:

Is there a better way of writing v = (v == 0 ? 1 : 0); [closed]

僤鯓⒐⒋嵵緔 提交于 2019-11-26 09:14:29
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed last year . I want to toggle a variable between 0 and 1. If it\'s 0 I want to set it to 1, else if it\'s 1 I want to set it to 0. This is such a fundamental operation that I write so often I\'d like to investigate the shortest, clearest possible way of doing it. Here\'s my best so far: v =

Button text toggle in jquery

不想你离开。 提交于 2019-11-26 08:59:29
问题 When i click \".pushme\" button, it turns its text to \"Don\'t push me\". I want to turn the text again to \"push me\" when button is clicked again. How can i do that? <html> <head> <script src=\"http://code.jquery.com/jquery-latest.js\"></script> </head> <body> <button class=\'pushme\'>PUSH ME</button> <script> $(\".pushme\").click(function () { $(this).text(\"DON\'T PUSH ME\"); }); </script> </body> </html> http://jsfiddle.net/DQK4v/ Thanks. 回答1: You can use text method: $(function(){ $("