toggleclass

jQuery 基础DOM和CSS操作

跟風遠走 提交于 2020-03-18 01:15:23
一、设置元素及内容 html() 获取元素中的HTML内容 html(value) 设置元素中的HTML内容 text()    获取元素中的文本内容 text(value) 设置元素中的文本内容 val()     获取表单中的文本内容 val(value) 设置表单中的文本内容 注意:当使用html()和text()设置元素的内容时,会清空原来的数据。如果希望追加信息,需要先获取原来的数据。 $('#box').html($('#box').html + 'extra html'); 如果想设置多个选定状态,比如下拉列表、单选复选框等,可以通过数组传递操作。 $("input").val(["check1","check2","radio1"]); //value值是这些的将被选定 二、元素属性操作 attr(key)            获取某个元素key属性的属性值 attr(key,value)         设置某个元素key属性的属性值 attr({key1:value1,key2:value2...}) 设置某个元素多个key属性的属性值 atrr(key,function(index,value){}) 设置某个元素key通过函数来设置 注意:attr()方法里面的function() {}可以不传参数。可以只传一个参数index,表示当前元素的索引(从0

JQuery干货篇之处理元素

大兔子大兔子 提交于 2020-03-17 11:54:22
JQuery干货篇之处理元素 注意这里用的还是我前两篇用的例子,详情请看 我的博客 attr attr() 方法设置或返回被选元素的属性值。 语法: $(selector).attr(attribute) 返回被选元素的属性值。 $(selector).attr(attribute,value) 设置被选元素的属性和值 $(selector).attr(attribute,function(index,oldvalue)) 设置被选元素的属性和值。 参数 描述 attribute 规定属性的名称。 function(index,oldvalue) 规定返回属性值的数。该函数可接收并使用选择器的 index 值和当前属性值。 实例: $("img").filter(":first").attr('src'); //得到属性 $("img").each(function (index,elem) { if(index%2==0) $(elem).attr("src",'lily.png'); //设置属性 console.log($(elem).attr("src")); }) $("img").attr('src',function (index,oldValue) { //这里的oldValue表示原来属性的值,index是索引 if(oldValue=="rose.png")

jQuery delay between each toggleclass

匆匆过客 提交于 2020-01-30 11:17:06
问题 I have made a (rather complicated) solution where I have 4 menu items pop in/out from the side and I make that happen by toggling a class. $('.menuitem').toggleClass('show'); It works great but the client now wants it to "slide out". I figured that I can make him happy if I can create a delay between each toggle, but I cant find a good way to do it. In practice I want each menu item to toggleClass but with a delay of maybe 250ms before next toggleClass. Edited - Apparently the delay function

jQuery addClass removeClass toggleClass hasClass is(.class)用法

岁酱吖の 提交于 2020-01-11 12:55:02
jQuery addClass removeClass toggleClass hasClass is(.class)用法 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/"; %> <!DOCTYPE html> <html> <head> <base href="<%=basePath%>"> <meta charset="UTF-8"> <title>b index</title> <link rel='stylesheet' type="text/css" href='b/css/bootstrap.css'> <style type="text/css"> .s1{ width: 100px; height: 100px; background-color: pink; } .s2{ width: 50px; height: 50px; background-color:

toggleClass(), index()

南楼画角 提交于 2020-01-07 03:47:40
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 1. toggleClass()对设置货已出被选元素的一个或多个类进行切换。该方法检查每个元素中指定的类,如果不存在则添加类,如果已设置则将之删除。这就是所谓的切换效果,不过通过“switch”参数,只能够规定只删除或者添加类。 语法:$(selector).toggleClass(class,switch) 参数 描述 class 必需。规定添加或移除 class 的指定元素。 如需规定若干 class,请使用空格来分隔类名。 switch 可选。布尔值。规定是否添加或移除 class。 使用函数来切换类 $(selector).toggleClass(function(){ },switch) 参数 描述 function(index,class) 必需。规定返回需要添加或删除的一个或多个类名的函数。 index - 可选。 接受选择器的 index 位置 。 class - 可选。接受选择器的当前的类。 switch 可选。布尔值。规定是否添加(true)或移除(false)类。 实例: <!DOCTYPE html> <html> <head> <title>test</title> <meta charset="utf-8"> <script type="text/javascript" src=

jQuery toggle() with toggleClass()

泪湿孤枕 提交于 2020-01-06 12:49:40
问题 I have a button that toggles a DIV layer on and off. I am trying to add a class to the button so that when its toggled on it appears differently, however I haven't been able to get it working, the class is not being added when the button is toggled. The button is a list item e.g. On / Off Here is my code: $("#btninformation").click(function () { $("#map-items-category-one").toggle("slow", function() { $(this).toggleClass("toggled-on"); }); }); Any ideas whats wrong with it? Thanks Zach 回答1:

Can this jQuery be done in vanilla JS?

大城市里の小女人 提交于 2020-01-05 14:24:43
问题 I've got this working on mobile devices, but because of the 32kb gzip-ed of jQuery I wonder if it's possible to create this code $(document).ready(function() { $('body').addClass('js'); var $menu = $('#menu'), $menulink = $('.menu-link'), $wrap = $('#wrap'); $menulink.click(function() { $menulink.toggleClass('active'); $wrap.toggleClass('active'); return false; }); }); can be written in no library dependany vanilla JavaScript. Can it be done? Where would I start? 回答1: JQuery uses javascript

how to toggle in between 2 classes in jquery?

纵然是瞬间 提交于 2019-12-29 09:21:46
问题 i have an issue doing toggleClass it doesn't seem to work properly. the image should change in between show and hide . It does change in to hide , but no back here is my example and some code: <div class="top_menu_hidden" style="display: none; ">testing</div> <div class="show_menu"></div> $('.show_menu').on('click', function(){ $('.top_menu_hidden').stop().slideToggle('normal', function(){ $(".show_menu").toggleClass("hide_menu show_menu"); }); });​ .show_menu{ background: url("http:/

save class state of multiple divs in cookie

让人想犯罪 __ 提交于 2019-12-25 18:42:45
问题 I have this toggleClass function: $(document).ready(function() { $("button#playersize").click(function(){ $("#wrapper").toggleClass("small large"); $(".divone").toggleClass("small large"); $(".divtwo").toggleClass("small large"); }); }); This changes the classes of the divs between "small" and "large" onclick button. I would like to save the class of the divs (#wrapper, .divone, .divtwo) to a cookie. And on reload, the class should be the saved one. How do I manage this? I have the jquery

JQuery Sibling Selector not Appending Class because of CSS

无人久伴 提交于 2019-12-24 07:08:01
问题 I have a menu with sub-menu child navigation as well, and I'm trying to append a class to the parent of the children based on the hovering of the children's <ul> container. This is what I have so far: http://jsfiddle.net/2KhnX/15/ but as you can see, the class never gets appended. If I strip most of the CSS from the HTML, but leave the class I'd like appended, it works fine - http://jsfiddle.net/2KhnX/21/ Which leaves me to believe that the CSS is conflicting or ruining the event that the