removeclass

Add/remove class on click to change background color of a div

半世苍凉 提交于 2021-01-27 19:27:25
问题 I've been trying to get a little black div to change color to green on click and change it back to black on the next click. I want it to keep doing this. Unfortunately it doesn't seem to work and through checking other topics on this I couldn't find my answer. My HTML: <div id="block"></div> My CSS: div { width: 100px; height: 100px; background-color: black; } My jQuery: $(function(){ $("#block").click(function(){ if($(this).hasClass("faded") == false) { $(this).css("background-color", "green

Sticky navbar makes content jump on way back up

荒凉一梦 提交于 2020-01-16 14:31:06
问题 I Have a simple site set up with a header, navbar and content. When the page reaches the navbar, the position becomes fixed so the navbar sits at the top of the page - at this point, the navbar height also gets a bit smaller (as I like this effect) - I have done this by adding separate classes, fixed and thinner to the navbar. Most people are aware of the issue that occurs when you add "position:fixed" to an inline element in that it makes the content suddenly "jump" upwards. To counteract

Add class if input is empty and remove it if not

久未见 提交于 2020-01-06 19:59:06
问题 I would like to add a class if input is empty and remove it if it isn't. I initially had addClass(); so I tried using: .removeClass().addClass(); But it doesn't seem to update the class on the click of the button. HTML: <input id="firstName" type="text" /> <input id="lastName" type="text" /> <a href="#" id="button">SEND</a> jQuery: var firstName = $("#firstName"); var lastName = $("#lastName"); $('#button').click(function () { if(firstName.val() == "" || lastName.val() == ""){ firstName

removeClass function doesn't work properly

流过昼夜 提交于 2020-01-05 15:05:16
问题 I wrote functions that allow the user to select and de select divs by clicking on them. Now, what i was trying to do was a function that, once pressed a , deselects everything, but it only deselect some of my divs. Here is the code: var divs = document.getElementsByClassName('fuori'); for(i = 0, j = divs.length; i < j; i++){ divs[i].addEventListener('click', function(){ if(!hasClass(this, 'selected')){ this.className = this.className + " selected"; } else { removeClass(this, 'selected'); } })

Print all tabs on a webpage

三世轮回 提交于 2020-01-05 03:27:45
问题 I have a survey with multiple tabs. When the user has completed the survey i want them to be able to print the survey or save it as a PDF. At the moment I can only print/save the tab that is opened. Is there a to remove the 'tab-content' when printing class using JavaScript so all the tabs are displayed code: http://codepen.io/pbuckleycork/pen/zvpMdr <div class="bs-example"> <ul class="nav nav-tabs tabs-custom"> <li class=""> <a href="#tab1" data-toggle="tab">User Info</a> </li> <li class=

IE7 and setAttribute() to remove classes

这一生的挚爱 提交于 2020-01-04 09:21:46
问题 I've got a pretty interesting issue. I'm writing a plugin which allows you to zoom in/out an image. I've got 3 buttons: close (close the 'window'), zoom in, zoom out. The buttons zoom in/out have got disabled versions, too. Its activated when you reach the minimum/maximum amount of zoom. If you open the picture to zoom, you can see an active zoom out button, and a disabled zoom in button (because I set the maximum value at opening). When you first clicked on the zoom out button, the zoom in

jquery add remove class onclick

时间秒杀一切 提交于 2019-12-31 09:05:01
问题 i have any navigation menu ! <div class="nav"> <ul class="navigation"> <li class="selected"><a href="#">HOME</a></li> <li><a href="#">PROFILE></a></li> <li><a href="#">CONTACTUS</a></li> <li><a href="#">ABOATUS</a></li> </ul> </div> Now how to add selected class after click to any ( profile, Contactus, aboutus ) and remove selected home using Jquery. Thanks 回答1: On the assumption that you want to have only one element of class-name selected I suggest: $('ul.navigation li a').click( function(e

Add and Remove class to click a dynamic Button

让人想犯罪 __ 提交于 2019-12-31 05:45:45
问题 Trying to Add and Remove class to click dynamic Buttons, means this button <button class="one"></button> get class dynamically like this: <button class="one text1">text1</button> So if button one has class .text1 and by click this add class .hide to list item <li class="text1"> like <li class="text1 show"> Same for button two <button class="two"></button> and by click add class <li class="text2 show"> Note: when click button two , then should remove class .show and add new class .hide to

Add and Remove class to click a dynamic Button

谁说我不能喝 提交于 2019-12-31 05:45:15
问题 Trying to Add and Remove class to click dynamic Buttons, means this button <button class="one"></button> get class dynamically like this: <button class="one text1">text1</button> So if button one has class .text1 and by click this add class .hide to list item <li class="text1"> like <li class="text1 show"> Same for button two <button class="two"></button> and by click add class <li class="text2 show"> Note: when click button two , then should remove class .show and add new class .hide to

JQuery addclass to selected div, remove class if another div is selected

烈酒焚心 提交于 2019-12-29 11:37:30
问题 I'm making a formbuilder, I would like to change the appearance of for example a heading div. When clicked it should get a border but when another dynamically generated div is clicked the class should be removed and the second clicked div has to get the .active class. How can I do this with generated divs? Anyway I found something that works but I still need the If another div is selected, previous div.removeclass and selected div.addclass This works: /* Add Class */ $(document).ready