custom-data-attribute

jQuery Validate custom messages

时光毁灭记忆、已成空白 提交于 2019-11-28 11:57:05
I have an input that I want to display a custom error message on when the user doesn't fill it out. <input type="text" class="foo" value="" data-prop="foo" data-rules="{ required: true }"></input> How do I add a custom error message to this specific input? Use: data-msg-required="Please enter something here!" Here's a demo HTML code: https://github.com/jzaefferer/jquery-validation/blob/master/demo/custom-messages-data-demo.html JS Fiddle demo: http://jsfiddle.net/leniel/VuPPy/48/ 来源: https://stackoverflow.com/questions/16681406/jquery-validate-custom-messages

How can I use a data attribute to set a background-image in CSS?

孤者浪人 提交于 2019-11-28 09:54:22
I have a folder with a few background images (one.jpg, two.jpg, three.jpg) , and this markup <section class="slide" data-bg="one"></section> <section class="slide" data-bg="two"></section> <section class="slide" data-bg="three"></section> Would it be possible somehow just with CSS to do something like this? .slide{ background-image: url(img/attr(data-bg).jpg); } This code isnt working, of course. oezi This won't be possible with pure css unless you're doing it the "undynamic" way: .slide[data-bg="one"]{ background-image: url('img/one.jpg'); } .slide[data-bg="two"]{ background-image: url('img

Remove multiple html5 data-attributes with jquery

我与影子孤独终老i 提交于 2019-11-27 17:37:58
问题 So jquery api says the following: Removing data from jQuery's internal .data() cache does not effect any HTML5 data- attributes in a document; use .removeAttr() to remove those. I have no problem removing a single data-attribute. <a title="title" data-loremIpsum="Ipsum" data-loremDolor="Dolor"></a> $('a').removeAttr('data-loremipsum'); The question is, how can I remove multiple data-attributes? More details: The starting point is that I have multiple ( let's say.. 60 ) different data

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

若如初见. 提交于 2019-11-27 15:59:35
问题 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

Get custom data-attribute in select2 with <select>

血红的双手。 提交于 2019-11-27 15:47:25
问题 Let's assume you have the following HTML5 <select id="example"> <option value="AA" data-id="143">AA</option> <option value="BB" data-id="344">BB</option> </select> $("#example").select2(); How do I get the data-id from the selected option ? 回答1: There is no direct method with select2, you can use a combinaison of select2 data and jQuery : $("#example").select2().find(":selected").data("id"); First you get the select2 data then you find your selected option with jQuery and finally the data

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

陌路散爱 提交于 2019-11-27 13:46:47
问题 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

Get data-attribute jquery vs javascript

…衆ロ難τιáo~ 提交于 2019-11-27 12:40:20
问题 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! 回答1: .data() doesn't operate on data attributes but in internal jQuery cache. Initially if no cache record

How to get, set and select elements with data attributes?

好久不见. 提交于 2019-11-27 12:09:48
问题 I'm having some trouble with data-attributes, I can't get anything to work for some reason so I must be doing something wrong: Set: $('#element').data('data1', '1'); //Actually in my case the data is been added manually Does that make a difference? Get: $('#element').data('data1'); Select: $('#element[data1 = 1]') None of this works for me, am I making this up or how is it? 回答1: All of the answers are correct, but I want to state something that nobody else did. The jQuery data method acts

Custom sorting on values in a data-sort attribute with Jquery Datatables

六眼飞鱼酱① 提交于 2019-11-27 12:08:37
问题 I have to do some custom sorts with Jquery Datatables. I do not want to write custom sort functions for every custom sort. I want to define a value to sort on and have Datatables ignore the original column values, if value is defined. For example: <td data-sort="111123">E 1.111,23</td> I want Jquery Datatables to sort this column numerically on 111123 . <td data-sort="19801220">20-12-1980</td> I want Jquery Datatables to sort this column numerically on 19801220 . <td>a string</td> I want

JQuery .data() not working?

纵饮孤独 提交于 2019-11-27 12:00:54
Recently I was coding away, and I ran into a weird issue. I was attempting to assign a data attribute to a new element I had created (via jQuery), only to discover it wouldn't actually assign the attribute. See the link below for an example, the code is listed below: http://jsfiddle.net/y95p100c/1/ Any idea why this is happening? I've never stumbled into this... var div = $("<div />") $(div).data("foo", "bar") console.log($(div)[0].outerHTML) // prints <div></div> data doesn't set data-* attributes. It manages a data cache unrelated to data-* attributes. It initializes from data-* attributes