addclass

jQuery performance, .css or addClass

纵饮孤独 提交于 2020-01-01 08:03:07
问题 I have a big jQuery code and I am thinking at speed performance of my functions. When an element is clicked (mousedown) i need to assign an image as background. I can do this by 2 ways: $('#element li.class').css({"background":"someimageURL"}); or $('#element li.class').addClass("someclass"); where "someclass" have the actual CSS background image. Witch function works better in this case. Is there a way to test various functions speed? Thank you 回答1: I'm almost certain .addClass() would be

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

Benefits of using attr() over addClass in jquery

给你一囗甜甜゛ 提交于 2019-12-28 04:08:10
问题 What are the benefits of using attr() instead of using addClass() in jquery? 回答1: When you use attr method to set the class of any element it will override the existing class name with whatever value you pass as the second argument to attr method. Where as if you use addClass method to add any class to an element it will just add the class and also retain the existing classes. If the class to add already exists then it will just ignore it. E.g. <div id="div1" class="oldClass"></div> Using $('

jQuery help for slideshow: adding a div for box-shadow effects has jQuery selecting the div

大兔子大兔子 提交于 2019-12-25 07:48:16
问题 So I used this place to help me create a slideshow, however, thanks to certain limits of CSS, you can't set a box-shadow property to IMG. However, the issue is thanks to the nature of the script, once it's done running through the IMGs, it encounters the div. The script is not supposed to encounter the div as the div is only used for decoration (again, since box-shadow can't be used for IMG). I was hoping someone would be able to help me with the formating of the code so as to ignore the

resize header on scroll

时光毁灭记忆、已成空白 提交于 2019-12-25 07:27:40
问题 I want to resize the header when the user scrolls and resize it again when the page is at the top. I have this example HTML <header class="header"> </header> <section> <p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p> <p>Pellentesque habitant morbi tristique

Get url path and add class active on li

筅森魡賤 提交于 2019-12-25 05:12:00
问题 I try to grab the url path and then add active class on li example: www.mysite.com/?p=xxxx the x will change depending on which link the user clicks on I tried this: <ul class="top_menu"> <li class="tider"><a href="/?p=1884">Åbningstider</a></li> <li class="butikker"><a href="/?p=1885">Butikker</a></li> <li class="sker"><a href="/?p=1886">Det sker</a></li> <li class="nyhedsbrev"><a href="/?p=1887">Nyhedsbrev</a></li> <li class="vej"><a href="/?p=1888">Find vej</a></li> </ul> var text = window

Add class into html tag by JQuery in ASP.NET C#

廉价感情. 提交于 2019-12-25 03:07:14
问题 I tried to add class in tag but when the web form postback it lost :( <ul> <li><asp:Linkbutton runat="server" Text="Text1"/></li> <li class="active"><asp:Linkbutton runat="server" Text="Text2"/></li> and this is my JQuery Code <script> $(document).ready(function () { $("li").click(function () { $("li").removeClass(); $(this).addClass("active"); }); }); </script> 回答1: Nothing that isn't runat="server" can be persisted; you need to store information about selected element (somewhere) - either