0

This is a revolution slider button.

I would like to get the "rs-26" from the data-actions attribute of a div. How can I get it using jQuery?

data-actions="[{"event":"click","action":"jumptoslide","slide":"rs-26","delay":""}]"

Rastalamm
  • 1,712
  • 3
  • 23
  • 32
Samad
  • 66
  • 5

1 Answers1

0

There are a few ways you can do this. Without knowing that your action div looks like, I assumed it was something like this:

<div id="theDiv" data-actions='[{"event":"click","action":"jumptoslide","slide":"rs-26","delay":""}]'>
    div with content
</div>

Then, the jQuery you would want could be something like this:

$(document).ready(function() {
    var actions = $("#theDiv").data("actions");
    var theSlide = actions[0].slide;
    console.log('The Slide: ' + theSlide);
});

I just used $(document).ready(function() { so that it would happen upon page load, but you can use that where you need it.

Here are a few additional resources that might help:

How to access JSON Object name/value?

Store JSON object in data attribute in HTML jQuery

How to get the data-id attribute?

cfnerd
  • 3,658
  • 12
  • 32
  • 44