addclass

jQuery: after adding class to a new element, can't trigger event by clicking on that class

时光怂恿深爱的人放手 提交于 2019-12-04 21:10:19
Here's what I'm attempting: when I click on an element with the class .main, that class is reassigned to the next element. When the next element (the new .main element) is clicked on, .main is reassigned to the next element, and so on. Here's my code: $('.main').click(function() { $(this).removeClass("main").addClass("other"); $(this).next().removeClass("other").addClass("main"); }); When I click on the original .main element, the class is transferred. However, clicking on the new .main element does not trigger the event again. What causes this? Am I going about this entirely the wrong way?

addClass to parent(LI)

你说的曾经没有我的故事 提交于 2019-12-04 13:34:55
问题 I have an element "A", when I click on it, I want to change parent element's ( LI ) class to selected , but nothing changes... $(".filters-list li a").click(function () { $(".filters-list li").removeClass("selected"); $(this).parent('li').addClass('selected'); // I also tried .parent().addClass }); Then I tried this code: $(".filters-list li a").click(function () { $(".filters-list li").removeClass("selected"); $(this).parent().get(0).addClass('selected'); // IE reports something like this:

If hasClass then addClass to parent

末鹿安然 提交于 2019-12-04 06:49:38
Original post: Why doesn't this simple script work? if ($('#navigation > ul > li > ul > li > a').hasClass('.active')) { $(this).parent().parent().parent().addClass(".active"); } EDIT: This won't hide the H1: if ($('#content h1').hasClass('aktiv')) { $(this).hide(); } Only this will: if ($('#content h1').hasClass('aktiv')) { $('#content h1').hide(); } Why can't I use the (this)? The dot is not part of the class name. It's only used in CSS/jQuery selector notation. Try this instead: if ($('#navigation a').hasClass('active')) { $(this).parent().addClass('active'); } If $(this) refers to that

JQuery adding class to cloned element

梦想的初衷 提交于 2019-12-04 03:54:31
This is my script: $('.addprop').click(function() { $('#clone').clone().insertAfter('.addprop'); }) I need to add a class to the new element that is being created. Is it possible? Yes, it is: $('.addprop').click(function() { $('#clone').clone().addClass('newClass').insertAfter('.addprop'); }) Although you're cloning an element based on its id , $('#clone') , so note that there will be two elements sharing the same id , which makes the result invalid HTML, so I'd suggest: $('.addprop').click(function() { $('#clone').clone().attr('id',id += 1).addClass('newClass').insertAfter('.addprop'); });

JQuery Find #ID, RemoveClass and AddClass

狂风中的少年 提交于 2019-12-04 00:02:18
I have the following HTML <div id="testID" class="test1"> <img id="testID2" class="test2" alt="" src="some-image.gif" /> </div> I basically want to get to #testID2 and replace .test2 class with .test3 class ? I tried jQuery('#testID2').find('.test2').replaceWith('.test3'); But this doesn't appear to work ? Any ideas ? jQuery('#testID2').find('.test2').replaceWith('.test3'); Semantically, you are selecting the element with the ID testID2 , then you are looking for any descendent elements with the class test2 (does not exist) and then you are replacing that element with another element (elements

addClass to parent(LI)

一笑奈何 提交于 2019-12-03 08:25:53
I have an element "A", when I click on it, I want to change parent element's ( LI ) class to selected , but nothing changes... $(".filters-list li a").click(function () { $(".filters-list li").removeClass("selected"); $(this).parent('li').addClass('selected'); // I also tried .parent().addClass }); Then I tried this code: $(".filters-list li a").click(function () { $(".filters-list li").removeClass("selected"); $(this).parent().get(0).addClass('selected'); // IE reports something like this: Object doesn't support addClass... }); When I tried to define LI with this code, it just reported me

jQuery : Add class dynamically depending on the browser window resolution

风格不统一 提交于 2019-12-03 04:38:46
问题 Hello friends I am trying to add a class to body dynamically depending on the browser window resolution. Here is the code I am trying to use but need help tuning it as I dont know jQuery at all. The options I want to achieve are : Once a visitor comes to my site, this code must check his browser windows size and add class to body as per the following rules If window size is more than 1024px but less than 1280px then add class .w1280 . If window size is more than 1280px but less than 1440px

Function work after second click

此生再无相见时 提交于 2019-12-03 00:42:00
问题 Anyboby help. Why function add class active this.parents(".block-parent").find(".periods[data-period="+typelink+"]").addClass('active') work after second click? need to be done after first click! link for not right example http://jsfiddle.net/kngU8/ Page.contentSort = function() { var $eachblocks = $(".top10_month .periods"); var $blockhead = $(".block-head__link"); $blockhead.on("click", function(e){ var $this = $(this); var typelink = $(".block-head__link.active").attr("data-date"); e

jQuery : Add class dynamically depending on the browser window resolution

自闭症网瘾萝莉.ら 提交于 2019-12-02 17:47:49
Hello friends I am trying to add a class to body dynamically depending on the browser window resolution. Here is the code I am trying to use but need help tuning it as I dont know jQuery at all. The options I want to achieve are : Once a visitor comes to my site, this code must check his browser windows size and add class to body as per the following rules If window size is more than 1024px but less than 1280px then add class .w1280 . If window size is more than 1280px but less than 1440px then add class .w1440 . If window size is more than 1440px but less than 1280px then add class .w1680 .

Function work after second click

泄露秘密 提交于 2019-12-02 14:31:40
Anyboby help. Why function add class active this.parents(".block-parent").find(".periods[data-period="+typelink+"]").addClass('active') work after second click? need to be done after first click! link for not right example http://jsfiddle.net/kngU8/ Page.contentSort = function() { var $eachblocks = $(".top10_month .periods"); var $blockhead = $(".block-head__link"); $blockhead.on("click", function(e){ var $this = $(this); var typelink = $(".block-head__link.active").attr("data-date"); e.preventDefault(); $this.parents("ul").find("a").removeClass("active"); this.className += " active"; $this