addclass

Add and Remove class to click a dynamic Button

蓝咒 提交于 2019-12-02 08:56:19
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 button one . Main HTML: <div id="main-id"> <button class="one"></button> <button class="two"></button> <ul>

jquery add / remove class from .parent()

夙愿已清 提交于 2019-12-01 10:54:26
i know this is incredibly easy but I have been writing and rewriting this function for an hour with no success: On click I want to add "active" to the <li> of the clicked link and remove "active" from all the other <li> 's in the navbar. HTML: <nav> <ul> <li><a href="http://0327ea8.netsolhost.com/#home" class="home">Home</a></li> <li><a href="http://0327ea8.netsolhost.com/blog/" class="blog">Blog</a></li> <li><a href="http://0327ea8.netsolhost.com/#catalog" class="catalog">Catalog</a></li> <li><a href="http://0327ea8.netsolhost.com/#authors" class="authors">Authors</a></li> <li><a href="http:/

jquery add / remove class from .parent()

♀尐吖头ヾ 提交于 2019-12-01 08:08:00
问题 i know this is incredibly easy but I have been writing and rewriting this function for an hour with no success: On click I want to add "active" to the <li> of the clicked link and remove "active" from all the other <li> 's in the navbar. HTML: <nav> <ul> <li><a href="http://0327ea8.netsolhost.com/#home" class="home">Home</a></li> <li><a href="http://0327ea8.netsolhost.com/blog/" class="blog">Blog</a></li> <li><a href="http://0327ea8.netsolhost.com/#catalog" class="catalog">Catalog</a></li>

if checkbox checked add class to parent element

守給你的承諾、 提交于 2019-12-01 05:56:53
I have a table with checkboxes looking like this: <td class="table-col" > <div class="group-one" > <input type="checkbox" /> </div> </td> What I want to do is when the checkbox is checked to apply a "selected" class to "table-col". if ($('.table-col').find(':checked')) { $(this).parent().parent().addClass('selected'); } I looked at many post with a similar solution like above but it doesn't seem work for me. I'm not sure why but this is pointing to HTMLDocument not the element. (edit) On this page there will be marked checkboxes, those which I want to apply "selected". On comments @cimmanon

Add class to parent div if there has specific class

喜夏-厌秋 提交于 2019-11-30 21:04:19
问题 Trying to add class to parent div <div class="widget-content"> if .widget-content li a has specific class .ifthis . HTML: <div class="widget-content"> <ul> <li><a href="https://twitter.com/slycolor" class="ifthis"> <b>This Text Should Red</b></a> </li> <li><a href="https://www.facebook.com/slycolor" class="ifthis"> <b>This Text Should Red</b></a> </li> </ul> </div> I have tried This: $('.widget-content li a').has('.ifthis').parent('.widget-content').addClass('social-sidebar'); But not working

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

♀尐吖头ヾ 提交于 2019-11-29 20:42:44
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(function() { $( document ).on( 'click', '.HeadingDiv', function () { /* This '.HeadingDiv' could be anything,

Add & remove active class from a navigation link

拥有回忆 提交于 2019-11-29 07:36:28
I have been looking for tutorials on how to add and remove a class from a link unfortunately without any success. All the earlier questions on this have give me some understanding, but haven't give me the result I want to accomplish. I'm trying to have an active state for my navigation, by adding and removing a class when the link is clicked. Here is what I have as far as JavaScript: $(document).ready(function(){ //active state $(function() { $('li a').click(function(e) { e.preventDefault(); var $this = $(this); $this.closest('li').children('a').removeClass('active'); $this.parent().addClass(

jQuery: Remove class if other element is clicked

喜夏-厌秋 提交于 2019-11-28 18:02:10
问题 I have an ul-list that contains li-elements. When the user clicks on one of these li elements a class should be added to that element. This is easy to setup, however, when the other li-element is clicked I want the "active"-class to be removed from the non-active li. I have made a jsfiddle of the problem: http://jsfiddle.net/tGW3D/ There should be one li-element that is red at any one time. If you click the second and then the first, only the first should be red. 回答1: This will remove the

Should I use “hasClass” before “addClass”? [duplicate]

允我心安 提交于 2019-11-28 17:41:27
This question already has an answer here: Check if class already assigned before adding 4 answers I have come across the following script which checks whether an element has class a , and if not, adds it: if (!$("div").hasClass("a")){ $("div").addClass("a"); } As jQuery won't add the class if it already exists, this could be changed to: $("div").addClass("a"); However, is there any performance improvements by using hasClass first, or is this using the same method which addClass does anyway, and therefore duplicating the logic? The .hasClass() check is not useful because jQuery will also always

How to add a callback function to the addClass method of jQuery?

霸气de小男生 提交于 2019-11-28 10:49:05
I'm using Prettify from Google and Markdown and I want each time I find a pre code added in the markdown textarea to call again the prettyPrint() function. This is my actual code: if($('#wmd-preview').length > 0) { $('#wmd-preview').on('DOMNodeInserted DOMNodeRemoved',function(){ $(this).find("pre").not('.prettyprint').addClass("prettyprint"); }); } But I want something like: $(this).find("pre").not('.prettyprint').addClass("prettyprint",function(){ prettyPrint(); }); Is there any possible way to achieve this? As far as I understand, you need this: $(this).find("pre").not('.prettyprint').each