JoshTalk
JoshTalk

Reputation: 67

How can I get the data from a div tag in jquery?

I'm trying to get the data-events value using jQuery and then change the background color of the div. This is my current situation:

<div class="fc-content" title="" data-events="Work In Progress"></div>
jQuery(document).ready(function($) {
    $("div[data-events='Work In Progress']").next().css('background-color:','#000000;'); 
});

The purpose is because I want to filter certain events that have a value of 'Work In Progress' and change background-color to black.

Upvotes: 0

Views: 48

Answers (2)

Thangaraja
Thangaraja

Reputation: 956

Use jQuery attribute selector

Change your code to

$("div[data-events='Work In Progress']" ).css('background-color', 'black');

Upvotes: 0

Christian Gerdes
Christian Gerdes

Reputation: 298

You can get the div by doing the following:

var eventInProgress = $("div[data-events='Work In Progress']");
eventInProgress.css("background-color", "#000000");

Upvotes: 1

Related Questions