FAQ Database Discussion Community


Select elements with data-attribute date value older than current server date

javascript,php,jquery,date,custom-data-attribute
I have a list of events that each have a custom data attribute containing a date: <ul class="event-list"> <li class="event-item" data-event-date="20150218"></li> <li class="event-item" data-event-date="20150522"></li> <li class="event-item" data-event-date="20150928"></li> </ul> <ul class="old-event-list"> </ul> What I'm trying to do is select all of the li.event-item elements within ul.event-list whose data-event-date attribute is older...

passing variable from data-attribute to onclick function

javascript,jquery,html,custom-data-attribute
I have a page with table of a number of records in it Each row has button on it I want to add an onclick event so it fires a popup message, if they ok it the page diverts to another page passing the value found in the data attribute...

Filtering elements using data attributes and input?

jquery,filter,custom-data-attribute
I am using this particular theme with my project and currently working with the chat functionality. Smart Admin Theme The Chat API beta has an input box which can basically be used to filter users but is just a dummy. I have given it an id of chat-filter and using...

jQuery.data(key) throwing undefined is not a function

jquery,html,custom-data-attribute
I have some checkboxes which are used to show/hide columns and automatically resize them to fit the screen. I've linked the checkboxes to their relevent columns using a data attribute and try to read this value using jQuery.data(). This gives an error of "undefined is not a function" even though...

Data attribute undefined

javascript,jquery,html,custom-data-attribute
I have a textbox and a checkbox: <input type="text" id="tb1" onFocus="CheckboxDisable('cb1');" /> <input type="checkbox" id="cb1" data-ieflub=""/> When the textbox comes into focus, I would like to disable the checkbox and set the data attribute ieflub to a value. My code is the following: function CheckboxDisable(id){ document.getElementById(id).disabled = true; $('#id').attr('ieflub', 'yes');...

jquery if image has attribute on click

jquery,custom-data-attribute
I am just learning how to use jquery correctly and I cannot seem to figure out why this approach doesn't stop the anchor from redirecting. Basically, I want to check if an image has a certain data tag in its anchor and when clicked it stops the link and does...

What is the best way to access an element through a data-attribute whose value is an object (JSON)?

javascript,jquery,json,custom-data-attribute
Say I have the following element: <div class='selector' data-object='{"primary_key":123, "foreign_key":456}'></div> If I run the following, I can see the object in the console. console.log($('.selector').data('object')); I can even access data like any other object. console.log($('selector').data('object').primary_key); //returns 123 Is there a way to select this element based on data in this attribute?...

Pass javascript function as data-* attribute and execute

javascript,jquery,custom-data-attribute
We know such syntaxes as below, when defining a value for onClick attribute: <button type="submit" onclick="alert('hi');"></button> <button type="submit" onclick="doWork"></button> <!-- This one doesn't work --> <button type="submit" onclick="doWork()"></button> <button type="submit" onclick="doWork('Mike', 2)"></button> What I'm interested in is to define a custom data-attribute and execute the value as follows: <button type="submit"...

Meteor.js: How to retrieve data attribute of parent element of an event object?

javascript,meteor,event-handling,custom-data-attribute
I want to build some kind of interactive week plan. I use an html table for displaying the plan. Each table row corresponds to one day of the week, while each table cell represents a certain part of the day (e.g. 'morning', 'noon' e.t.c.). The table is rendered in a...

Escape/Special Characters from user input to HTML5 data-attributes using URL Encode/Decode

javascript,jquery,ajax,json,custom-data-attribute
This is my first question on stackoverflow - needing help from all you experts. Our web app allows the user to input escape/special characters. We are doing some testing for extreme cases. I'm able to pass the escape characters through ajax/json. var test = JSON.stringify({ typeName: $("#typeName").val(), invoiceType: 'NewTypeArea' });...

Replace ajax url with clicked element which have data attribute

jquery,ajax,html5,custom-data-attribute
My question is very simple for jquery lovers, but hard for me. I have simple a href tag with data atrribute included. <a href="#/one" data-menu-button="menu1" class="button">menu 1</a> <a href="#/two" data-menu-button="menu2" class="button">menu 2</a> // etc Also i have very simple ajax call script. $(".button").click(function(){ $.ajax({url: "test.php", success: function(result){ $(".page").html(result); }}); });...

How to retrieve HTML5 data-* Attributes using C#

c#,asp.net,html5,code-behind,custom-data-attribute
I have a asp checkbox in my form: <asp:CheckBox id="option" runat="server" OnCheckedChanged="checkChange" data-attributeA="somevalue1" data-attributeB="somevalue2" AutoPostBack="true" />` In my OnCheckedChanged event I want to retrieve these two data-attributes. protected void checkChange(object sender, EventArgs e) {} How do I do that?...

ASP.NET code snippit to query database for unique field value

asp.net,asp.net-mvc,custom-data-attribute
I'm trying to create custom remote data annotation to check for unique values. So far I have: [Remote("checkForUniqueSpeciesName", "Create", ErrorMessage = "A Species by that name already exists.")] public string SpeciesName { get; set; } and public ActionResult checkForUniqueSpeciesName(string species_name) { bool is_unique = ........ return Json(is_unique, JsonRequestBehavior.AllowGet); } To...

How can I loop through a nested UL to do an attribute comparison?

jquery,html,custom-data-attribute
On my HTML page, I have a nested unordered list, where each list item may or may not have an attribute called data-roles. If I have a comparison variable, read from an input element (lets call it the strComparison variable to keep it simple), then how can I use jQuery...

How to get data attribute with jQuery .each()

javascript,jquery,custom-data-attribute
I work on a portfolio where there a few people. Each person has a demo and a click on the person should lead to the video. My problem is that it returns the same videoid for everyone. Here is what looks like a person container (I got 8 of them)....

Add dynamic data-attribute with jQuery

jquery,html,custom-data-attribute
Is there a way to add a "dynamic" data-attribute to a DOM element with jQuery? This, for example, doesn't work: var value = 100; // hoping to add a 'data-100' attribute $('div').attr({ String('data-' + value) :'display: block' }); It throws the error: Uncaught SyntaxError: Unexpected token ( obs: as far...

JavaScript Accordion Menu with querySelectorAll()

javascript,toggle,accordion,custom-data-attribute,queryselectorall
I'm attempting to build an accordion menu using querySelectorAll() but unsure what the best method would be to check if the clicked list item's children (.toggleContent and .toggleIcon) belong to it's clicked parent toggle_li[i]. Correct me if I am wrong, but I assume that controlling this within the onclick function...

Parsing HTML5 data-* attribute values with Selenium in Python

python,html5,parsing,selenium,custom-data-attribute
I am parsing a JS generated webpage like so: from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC driver = webdriver.Firefox()...

Get a div by two data attributes and by exclude data attributtes

javascript,jquery,html,custom-data-attribute
I have some divs like these: <div id="1" data-effect-in="swing" data-effect-out="bounce"></div> <div id="2" data-effect-in="swing"></div> <div id="3" data-effect-out="swing"></div> <div id="4" data-effect-out data-effect-in="swing"></div> <div id="5" data-effect-in data-effect-out="fadeIn"></div> jsFiddle I need to get using jQuery the divs that have data-effect-in AND data-effect-out and these attributes have values not empty. Added requirement I need too...