attr

Does jQuery attr allow for non standards?

邮差的信 提交于 2019-12-12 17:31:31
问题 I am already using id and title but i need to parse through 2 more bits... $(this).attr("title"); $(this).attr("id"); Will $(this).attr("custom1"); work ?? 回答1: yes, and BTW you can set multiple attributes at once: $('.myselector').attr({ src: 'thefile.gif', width: 200, height: 300 }); 回答2: Yes, and you can use it for all of the data-attributes in HTML5. Which is the preferrable way to add extra attributes. Additionally, all data-* attributes are automatically added to jQuery's data() object

jQuery attr in IE7

时光怂恿深爱的人放手 提交于 2019-12-12 06:13:20
问题 I have the following HTML: <a href="myPage.htm"> <img src="anImage.jpg /> </a> <a href="yourPage.htm"> <img src="anotherImage.jpg /> </a> <a href="everyonesPage.htm"> <img src="stillAnotherImage.jpg /> </a> And the following javascript (using jQuery): $(document).ready(function(){ $('a').live('click', function(e){ e.preventDefault(); alert($('img', this).attr('src')); }); }); In Firefox this alerts the src attribute of the image clicked, but in IE7 and IE6 it alerts 'undefined'. Any ideas why

getting attribute of an element with its corresponding Id

喜欢而已 提交于 2019-12-12 05:19:49
问题 suppose that i have this xml file : <article-set xmlns:ns0="http://casfwcewf.xsd" format-version="5"> <article> <article id="11234"> <source> <hostname>some hostname for 11234</hostname> </source> <feed> <type weight=0.32>RSS</type> </feed> <uri>some uri for 11234</uri> </article> <article id="63563"> <source> <hostname>some hostname for 63563 </hostname> </source> <feed> <type weight=0.86>RSS</type> </feed> <uri>some uri for 63563</uri> </article> . . . </article></article-set> what I want,

Raising errors in attribute accessor overrides?

不想你离开。 提交于 2019-12-12 03:58:16
问题 I am overriding an attribute accessor in ActiveRecord to convert a string in the format "hh:mm:ss" into seconds. Here is my code: class Call < ActiveRecord::Base attr_accessible :duration def duration=(val) begin result = val.to_s.split(/:/) .map { |t| Integer(t) } .reverse .zip([60**0, 60**1, 60**2]) .map { |i,j| i*j } .inject(:+) rescue ArgumentError #TODO: How can I correctly report this error? errors.add(:duration, "Duration #{val} is not valid.") end write_attribute(:duration, result)

When jQuery .attr('onclick') function return a event object?

荒凉一梦 提交于 2019-12-12 02:39:06
问题 I am just debugging jQuery in FireBug and wonderig about the return value of $('.a-selector').attr('onclick'); It turns out to be an onclick(event) , but I have read some code before and the author just uses it like this: $('.a-selector').attr('onclick').replace(..., ...); which means it can be treated as a String Object. But it reports an error when I use like this. My jQuery version is 1.5.2. So I wonder when the jQuery changes the API and what is the best way to change the onclick event

What is the advantage of using 'data-attribute' over $.data in jQuery?

不打扰是莪最后的温柔 提交于 2019-12-11 10:45:33
问题 I was wondering what the advantage is of using data assignment to the DOM vs. NOT to the DOM i.e. Assume we have said HTML <a id="foo" href="#">foo!</a> //Set attr data-me so it's <a id="foo" data-me="yay" href="#">foo!</a> $('#foo').attr('data-me', 'yay'); //Retrieve the data 'yay' $('#foo').data('data-me'); Over and above direct assignment: var myInput = $('#foo'); //Add some data $.data(myInput, 'data-me', 'yay'); //Retrieve the data 'yay' $.data(myInput, 'data-me'); My understanding is

loop through all elements (dynamically driven content) if they all still have special attrbitue

帅比萌擦擦* 提交于 2019-12-11 08:42:20
问题 The thing I need (prob with Jquery) is to loop through all elements in my ul (dynamically driven content) if they all still have this special attrbitue pl_id (the value may vary) If all elements within this ul still contain the attribute then the button still needs to be in place. If one element is added the button has to disappear... I'm confused how to approach this. <ul id="tracks"> <li pl_id="14" class="item" id="5" ytid="SnA52s7qceM" artist="Michael Bublé" albname="Christmas" track=

False True change attr by onclick jQuery

 ̄綄美尐妖づ 提交于 2019-12-11 04:25:26
问题 I need to change data attribute "aria-selected" by oncklick. But this script does not work. Could you help me, please? <a href="#" aria-selected="true" resource="">SHOW/HIDE</a> And here is my code: <script> $(document).ready(function($){ $("a").attr("aria-selected","false"); $(" ul li a").addClass("accordion"); $('.accordion').click(function() { if ($(this).attr('aria-selected')) { $(this).attr("aria-selected","true"); } else { $(this).attr("aria-selected", "false"); } }); }); </script> 回答1:

jQuery .attr() seems to be case sensitive

旧城冷巷雨未停 提交于 2019-12-11 01:54:59
问题 I have a select element with few custom attributes that I use to validate it on the fly and display appropriate messages. Attribute's name is camel cased as in <select validationMessage="Must select something" ... >... The problem is that in jQuery version older than 1.6 .attr() seems to be case sensitive. What's even more problematic, that it won't fetch originally cased attributes. This works the same in Firefox in Chrome, but works as expected (case insensitive as it should be) in Internet

attr() not working in IE

只愿长相守 提交于 2019-12-11 01:34:00
问题 after browsing some similar question on here I couldn't find anything to help me fix my problem. In Chrome it works, get to IE and I get "aN,AN,NAN" the HTML <div class="dateSelect"> <div class="prev"> <a class="prevMonth" name="05,27,2013">month</a> </div> </div> the jQuery $(".dateSelect a").click(function(event){ var dateParam = $(this).attr('name'); alert("link was clicked and value of NAME is: "+dateParam); dateChange(dateParam); event = event || window.event; event.stopPropagation(); })