custom-data-attribute

Storing data in the DOM

风流意气都作罢 提交于 2019-12-01 04:19:54
问题 I have a list of books and I want to store data against each book e.g. Price, Quantity, id, catergory id, size, weight etc. I was looking at storing all this in the dom by extending the li elements representing each book in the list using data- attributes. This data could then be utilised directly with javascript. However I have read that accessing data- attributes is slow in a performance sense. In addition I can have multiple instances of the same book so am a little concerened about bloat

CSS data attribute conditional value selector?

别等时光非礼了梦想. 提交于 2019-11-30 18:38:01
Given html such as : <div data-points="800">Jonh</div> <div data-points="200">Jack</div> <div data-points="1200">Julian</div> How to select elements were the value is superior to 1000 (x>1000) ? Preference : via CSS selectors. If no such thing, then I will re-ask for a JQuery / JS answer. Eventually used : var x = 1000; $("div").each(function() { if ($(this).attr('data-points') > x) { $(this).addClass('larger-than-x'); // Or whatever } }); With CSS you can select elements with their attributes: div[data-points] { } or the value of their attributes: div[data-points="800"] { } but you can't use

Is Google indexing HTML custom data attributes?

岁酱吖の 提交于 2019-11-30 17:31:19
问题 I'm building an AJAX based portfolio module using pushState / hash bangs and as I'm ruling out browsers without JavaScript the only thing that concerns me is how limited the HTML custom data attributes are when it comes to SEO. For example, using the code below: <ul class="gallery" data-anchor="/photography/example/" data-title="Example"></ul> Will the data-title be indexed, i.e. will that text content be gathered by Google? Or would I need to include a header tag in or around the list as a

Set custom data- attributes on {{#linkTo}} helper <a> tag

强颜欢笑 提交于 2019-11-30 06:29:55
How can I set custom data- attribute on the {{#linkTo}} helper? I want use this: {{#linkTo "foo" data-toggle="dropdown"}}foo{{/linkTo}} and the result should look like this: <a id="ember323" class="ember-view active" data-toggle="dropdown" href="#/foo/123">foo</a> but it looks like: <a id="ember323" class="ember-view active" href="#/foo/123">foo</a> How can I do this? intuitivepixel A way you could do this is to extend your Ember.LinkComponent to be aware of the new attribute: Ember.LinkComponent.reopen({ attributeBindings: ['data-toggle'] }); And then you can use it in your {{#link-to}}

CSS data attribute conditional value selector?

痞子三分冷 提交于 2019-11-30 02:58:43
问题 Given html such as : <div data-points="800">Jonh</div> <div data-points="200">Jack</div> <div data-points="1200">Julian</div> How to select elements were the value is superior to 1000 (x>1000) ? Preference : via CSS selectors. If no such thing, then I will re-ask for a JQuery / JS answer. Eventually used : var x = 1000; $("div").each(function() { if ($(this).attr('data-points') > x) { $(this).addClass('larger-than-x'); // Or whatever } }); 回答1: With CSS you can select elements with their

How to do data- attributes with haml and rails?

泪湿孤枕 提交于 2019-11-29 16:04:42
问题 I can have %a{href: '#', data_toggle_description_length: 'toggle_me_ajax'} which it gives me underscores not dashes, i.e. <a href="#" data_toggle_description_length="toggle_me_ajax"></a> However I want to have HTML5 data- attributes, i.e. <a href="#" data-toggle-description-length="toggle_me_ajax"></a> but when I try replacing underscores with dashes, i.e. %a{href: '#', data-toggle-description-length: 'toggle_me_ajax'} I get syntax errors: /home/durrantm/Dropnot/webs/rails_apps/linker/app

Case sensitive in data attribute

余生颓废 提交于 2019-11-29 14:55:53
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://jsfiddle.net/qhoc/7dExt/1/ I think it has to do with the fact that data-* explicitly prevents the data key

jQuery's data() attribute does not update when element data changes

你说的曾经没有我的故事 提交于 2019-11-29 05:55:49
I wanna use jQuery's data() api to retrieve all the data attribute of an element. But the cache nature of this api is really annoying. Sometimes I need to change some data atribute of an element in javascript but the data() api always return the initial value of each data attribute. So I have to use the attr() to access each data attribute of an element to get its up-to-date value. Is there any way to overcome this cache thing and make data() always return the latest value every time I call it? The short answer is: don't use jQuery .data() for dynamically set data attributes, unless you can

what is the purpose and usage of data-value, data-title, data-original-title, original-title, etc.?

妖精的绣舞 提交于 2019-11-28 21:24:32
I've been seeing these attributes around on more modern websites like GitHub and such, and they always seemed to coincide with a customized popover like the title attribute. <a href="/" data-value="hovering message">Option 1</a> <a href="/" data-title="hovering message">Option 2</a> <a href="/" data-original-title="hovering message">Option 3</a> <a href="/" original-title="hovering message">Option 4</a> I read some documents about data- attributes on HTML5 Doctor, and I'm not quite sure of the point. Is there some SEO or accessibility benefit to using them? And what is the plugin(hopefully

Get data-attribute jquery vs javascript

与世无争的帅哥 提交于 2019-11-28 20:02:50
I have a custom data-attribute set by default: data-equipment="0" If i change it with jquery using .data() $(this).data("equipment", 10) and then use the getAttribute() this.getAttribute("data-equipment") i get the old value (0) and not the new one (10). But if i use $(this).data("equipment") i get the new value (10). Is this supposed to work like this or am i missing something? Thanks! .data() doesn't operate on data attributes but in internal jQuery cache. Initially if no cache record is found, the data is read from a corresponding data- attribute if one exists, but that is the end of their