attr

jQuery attr() fails to set attribute

吃可爱长大的小学妹 提交于 2019-12-06 18:18:20
问题 I am trying to rotate an image via svg's transform . This is the code I have: <svg width="100" height="100"> <image id="trns" transform="rotate(90,50,50)" width="100" height="100" xlink:href="logo.png"/> </svg> This successfully rotates logo.png by 90 degrees when the page loads. Also, when I change 90 to a different number in firbug's HTML tab the rotation changes accordingly. But when I try to change the value with jQuery, nothing happens: $('#trns').attr('transform', 'rotate(60, 50,50)');

Get value of custom attribute

好久不见. 提交于 2019-12-06 16:36:49
问题 I have two radio buttons. I would like to be able to get the value of the custom attribute "xmlvalue" of the checked radio button. I have tried with the following script: var userType = $("input[name=ctrl_CustomerType]:checked", this).attr('xmlvalue'); Markup: <input type="radio" name="ctrl_CustomerType" id="ctrl_CustomerType_1" xmltag="CustomerType" xmlvalue="existingCustomer" checked="checked"> Yes <br /> <input type="radio" name="ctrl_CustomerType" id="ctrl_CustomerType_2" xmltag=

Transform input type text to password [duplicate]

☆樱花仙子☆ 提交于 2019-12-06 07:35:50
This question already has answers here : Changing the type of an input field using jQuery (text -> password) (5 answers) Closed 6 years ago . I want to change the input type to password when I click on it. I tried this: <input name="pin" id="cp_serv" type="text" class="pin_v" value="Insert PIN Please" onclick="this.value='';$(this).attr('type','password');"/> I tried to use the jQuery function attr to change this on the click event, but nothing is happening. Is this the right way to do it or is this possible? 26ph19 This will work $('input').on('click', function () { $(this).attr('type',

Use 'alt' value to dynamically set 'title'

一笑奈何 提交于 2019-12-06 05:26:10
I need some help, and before we get going, I know it is probably not best practice, but I am doing some maintenance to an existing site and need to accomplish the following for a fix. <a rel="lightbox" href="site.com" title="a generated title"> <img src="site.com/img" class="post-image" alt="a long description"/> </a> Okay, so I am trying to figure out how to use jQuery or any other method to take the alt attribute from my image, and dynamically overwrite the title attribute of my a tag. Any help would be awesome, I am kinda lost at this juncture. $(function(){ $("a").each(function(){ $(this)

Adding attributes in chaining way in dplyr package

安稳与你 提交于 2019-12-06 03:31:18
问题 Is there any way to add an attribute using chaining sequence code operator %>% from dplyr package? > library(dplyr) > iris %>% + attr( "date") = Sys.Date() Error in iris %>% attr("date") = Sys.Date() : could not find function "%>%<-" > Thanks for respone. 回答1: You can also consider setattr from "data.table": library(dplyr) library(data.table) names(attributes(iris)) # [1] "names" "row.names" "class" iris %>% setattr(., "date", Sys.Date()) names(attributes(iris)) # [1] "names" "row.names"

Delete all classes after a certain class

自闭症网瘾萝莉.ら 提交于 2019-12-05 22:41:08
I have a < div id="thisdiv" class="class1 class2 class3 class4 class5"> text < /div> I need to be able to delete all classes after class3 with jQuery. something like $('#thisdiv').removeClass(all after class3); OR $('#thisdiv').attr('class', all from class1 to class3); Please how can I do that? You can try the following, but your classes might not be in the same order as they appear in the HTML source: $('#thisdiv').attr('class', function(i, v) { var classes = v.split(' '), position = $.inArray('class3', classes); return classes.slice(0, position + 1).join(' '); }); Here's the fiddle: http:/

Jquery length of attribute undefined

北慕城南 提交于 2019-12-05 20:03:20
How can I check the lenght of the string that is in the attribute?This shows 'undefined' value: var action = $(obj).closest("form").attr('action'); alert(action.lenght); Your spelling is just a bit off, .lenght should be .length : var action = $(obj).closest("form").attr('action'); alert(action.length); Always goto api when some method is not found before you make a post somewhere. http://api.jquery.com http://api.jquery.com/length/ 来源: https://stackoverflow.com/questions/4376276/jquery-length-of-attribute-undefined

jquery prop方法的使用以及与attr方法的区别

对着背影说爱祢 提交于 2019-12-05 19:52:50
prop方法的概况: prop()是jquery1.6中新加了一个方法,用来区分attr方法,专门用来处理DOM属性。一些内置属性的DOM元素或window对象,如果试图将删除该属性,浏览器可能会产生错误,而prop方法则可以避免这种错误发生。换言之,prop可以说是为了处理DOM属性(如 selectedIndex, tagName, nodeName, nodeType, ownerDocument, defaultChecked, 和 defaultSelected)而产生的。 prop的用法: 返回属性的值: $(selector).prop(property) // EXP <input type=‘checkbox’> <button>查看</button> <script> $(“button”).click(function(){ $(“input”).prop(‘checked’); }); //input选中点“查看”返回true //input未选中点“查看”返回false </script> 设置属性和值: $(selector).prop(property,value) // EXP <input type=‘checkbox’> <button>选中</button> <script> $(“button”).click(function(){ $(

Get value of custom attribute

本小妞迷上赌 提交于 2019-12-04 23:43:54
I have two radio buttons. I would like to be able to get the value of the custom attribute "xmlvalue" of the checked radio button. I have tried with the following script: var userType = $("input[name=ctrl_CustomerType]:checked", this).attr('xmlvalue'); Markup: <input type="radio" name="ctrl_CustomerType" id="ctrl_CustomerType_1" xmltag="CustomerType" xmlvalue="existingCustomer" checked="checked"> Yes <br /> <input type="radio" name="ctrl_CustomerType" id="ctrl_CustomerType_2" xmltag="CustomerType" xmlvalue="newCustomer"> No Fiddle here -- But I keep getting "Undefined". Any ideas? Remove the

jQuery attr() fails to set attribute

假装没事ソ 提交于 2019-12-04 23:35:30
I am trying to rotate an image via svg's transform . This is the code I have: <svg width="100" height="100"> <image id="trns" transform="rotate(90,50,50)" width="100" height="100" xlink:href="logo.png"/> </svg> This successfully rotates logo.png by 90 degrees when the page loads. Also, when I change 90 to a different number in firbug's HTML tab the rotation changes accordingly. But when I try to change the value with jQuery, nothing happens: $('#trns').attr('transform', 'rotate(60, 50,50)'); What does firebug do that my attr line does not? Working fine here (with jQuery 1.6.2): http://jsfiddle