custom-data-attribute

Select elements by data attribute in CSS

亡梦爱人 提交于 2020-02-16 10:42:32
问题 Is it possible to select elements in CSS by their HTML5 data attributes (for example, data-role )? 回答1: If you mean using an attribute selector, sure, why not: [data-role="page"] { /* Styles */ } There are a variety of attribute selectors you can use for various scenarios which are all covered in the document I link to. Note that, despite custom data attributes being a "new HTML5 feature", browsers typically don't have any problems supporting non-standard attributes, so you should be able to

change data-attribute using jquery

纵饮孤独 提交于 2020-02-02 06:05:08
问题 How can I change <div data-300=""></div> to <div data-500=""></div> using jquery? I don't want to remove the attribute and replace it as it contains data I need I just need to change the '300' to '500'. 回答1: Not generic at all, but it should do the job var $target = $('div[data-300]'), oldData = $target.data('300'); $target.removeAttr('data-300').attr({ 'data-500': oldData }); 回答2: Here's a function you can use: function attrChangeName(elem, attr, new_attr) { var data = $(elem).attr(attr); $

change data-attribute using jquery

霸气de小男生 提交于 2020-02-02 06:04:43
问题 How can I change <div data-300=""></div> to <div data-500=""></div> using jquery? I don't want to remove the attribute and replace it as it contains data I need I just need to change the '300' to '500'. 回答1: Not generic at all, but it should do the job var $target = $('div[data-300]'), oldData = $target.data('300'); $target.removeAttr('data-300').attr({ 'data-500': oldData }); 回答2: Here's a function you can use: function attrChangeName(elem, attr, new_attr) { var data = $(elem).attr(attr); $

change data-attribute using jquery

拈花ヽ惹草 提交于 2020-02-02 06:04:35
问题 How can I change <div data-300=""></div> to <div data-500=""></div> using jquery? I don't want to remove the attribute and replace it as it contains data I need I just need to change the '300' to '500'. 回答1: Not generic at all, but it should do the job var $target = $('div[data-300]'), oldData = $target.data('300'); $target.removeAttr('data-300').attr({ 'data-500': oldData }); 回答2: Here's a function you can use: function attrChangeName(elem, attr, new_attr) { var data = $(elem).attr(attr); $

change data-attribute using jquery

假装没事ソ 提交于 2020-02-02 06:04:20
问题 How can I change <div data-300=""></div> to <div data-500=""></div> using jquery? I don't want to remove the attribute and replace it as it contains data I need I just need to change the '300' to '500'. 回答1: Not generic at all, but it should do the job var $target = $('div[data-300]'), oldData = $target.data('300'); $target.removeAttr('data-300').attr({ 'data-500': oldData }); 回答2: Here's a function you can use: function attrChangeName(elem, attr, new_attr) { var data = $(elem).attr(attr); $

Custom data in XHTML 1.0 Strict

♀尐吖头ヾ 提交于 2020-01-14 08:03:48
问题 I use some custom attributes in my html, for jquery stuff. I saw there are data-XYZ attributes in HTML5, but I need to be xhtml 1.0 strict. What other options do I have? 回答1: You can use the jQuery MetaData plugin which allows you to write data in the class attribute in JSON format: <li class="someclass {some: 'data'} anotherclass">...</li> Then in your jQuery, to get at the data: var data = $('li.someclass').metadata(); if ( data.some && data.some == 'data' ) alert('It Worked!'); This should

Delete links stopped working data-method='delete' but goes to show page

孤街醉人 提交于 2020-01-13 05:19:31
问题 I just noticed that all the various delete links in my application now just go to show pages. This application began as rails 2.3.8, it is now rails 3.2.17 Examples of the rails code: Controllers, def destroy @group = Group.find(params[:id]) @group.destroy respond_to do |format| format.html { redirect_to(groups_url) } format.xml { head :ok } end end And, def destroy @link = Link.find(params[:id]) @link.destroy respond_to do |format| format.html { redirect_to(links_url) } end end Which

Case sensitive in data attribute

天大地大妈咪最大 提交于 2020-01-10 05:13:10
问题 Well it must be late and my brain got numb. How come jQuery doesn't recognize case sensitive in data attribute? I faced this annoying problem: HTML: <a data-showId="12345">Test 1</a> Javascript: console.log($('a').data('showId')); console.log($('a').data('showid')); The first line is undefined and second returned 12345 correctly. I thought it supposed to returned correctly in first line and undefined in second. So does it mean all data- attr must be lowercase? Check it out here http:/

How can I use HTML5 Data Attributes in XHTML?

我的未来我决定 提交于 2020-01-03 08:36:18
问题 Does anyone know how the HTML5 data attributes ( data-* ) can be implemented in XHTML without rendering the markup as invalid? Is there a custom namespacing hack that would allow this on existing HTML elements? 回答1: You could use XHTML5. Then your mark-up would be XML, and valid XHTML5. I think you could also use XML namespacing to use them on XHTML1 — I’m not very familiar with XML, so I’m not sure. I think that both of these methods technically require you to serve your pages as XML

Selecting custom data attributes in JQuery

爷,独闯天下 提交于 2020-01-02 01:48:14
问题 I have a list here <ul id="demo2" data-name="demo2"> <li data-value="here">here</li> <li data-value="are">are</li> <li data-value="some...">some</li> <!-- notice that this tag is setting a different value :) --> <li data-value="initial">initial</li> <li data-value="tags">tags</li> </ul> Where each li item has a custom data attribute. On JQuery how would get all of the values of each li element which has an attribute of data-value? I want to get their value. but this code of mine doesn't seem