0

I need to know how to .append a data-reactid being outputted by a Wordpress plugin application. The example below shows the code that is successfully appending to a div with the id of #div1. This is working great.

How do I perform the same function but append to a specific data-reactid?

<script type="text/javascript">
jQuery(document).ready(function ($) {
$('#div1').append('<div>Some HTML</div>');
});
</script>
  • Possible duplicate of [jquery data selector](https://stackoverflow.com/questions/2891452/jquery-data-selector) – sushain97 Feb 20 '18 at 18:12
  • why would you want to do this? There is probably a more predictable way to accomplish what you need. data-reactid is not used in modern React, so even if it was possible to use it as a jQuery selector (which I dont think it is) theres a large change the person maintaining that app will update their react version and you would lose access to that attribute entirely – Robbie Milejczak Feb 20 '18 at 18:25
  • Robbie! Thank you so much for your response. I would love to do this in the easiest most "right" way possible. With the code I'm using above, I simply cannot get it to append to a div that is rendered by React. Any suggestions? Thank you. – Tim Krukowski Feb 20 '18 at 18:45
  • I understand that the app developer could change his react scheme, but I do know for sure that the class of the div that i want to append (shove content after) will not change. – Tim Krukowski Feb 20 '18 at 18:46

1 Answers1

0

This should work:

$('[data-reactid="YOUR_REACT_ID"]').append('<div>Some html</div>');

jCobb
  • 238
  • 1
  • 9