0
<div data-react-class="Duration" data-react-props="{"startDate":"","endDate":""}">

I have this in my html. How can I change the startDate and endDate values in data-react-props using jquery?

2
  • Is it running allright? Because your "{"startDate" should break (wrong "). Well, for changing these values with jQuery, maybe a simple var element = $('selector'); // var data = element.data('react-props'); // data['startDate'] = new value; // element.data('react-props', data); // that should do Commented Sep 10, 2017 at 23:44
  • it is created by react-rails helper and its working fine Commented Sep 10, 2017 at 23:56

2 Answers 2

2

add an ID to the div:

<div id="sample" data-react-class="Duration" data-react-props="{"startDate":"","endDate":""}">

And use the setAttribute method:

document.getElementsByID('sample').setAttribute('data-react-props', '{"startDate":"","endDate":""}');
Sign up to request clarification or add additional context in comments.

Comments

1

You can use jQuery data selectors

$("div[data-react-class='duration']").attr("data-react-props","{'startDate':'12-12-2017', 'endDate':'01-01-2018'}");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.