0

I have a plugin that generates tables based on mysql queries. The plugin generated a shortcode that I put in posts to show the tables.

Above the table there is a button that has a span. the span text is Columns.

I want to change the text from Columns to This is my new Text. There is no way to do this in the plugin options and I contacted the developer who confirmed this.

I inspected the button and obtained its class, then I used the following jQuery:

    <script type="text/javascript">
jQuery( document ).ready(function() {
jQuery(".buttons-collection.buttons-colvis.DTTT_button.DTTT_button_colvis span ").text(" This is My New Text ");
});
</script>

The code works fine, except that it changes the text of that button in all the tables, which is something I don't want. I want to change the text on some buttons only, based on the content of the table.

I tried putting the shortcode inside a div tag like this:

<div class="new-class">[plugin shortcode]</div>

Then I added the class to the jQyery like this:

jQuery(".new-class.buttons-collection.buttons-colvis.DTTT_button.DTTT_button_colvis span ").text(" This is My New Text ");

But it did not work. It showed the default text Columns.

I think that the problem is that the classes in the code that worked are classes of the button itself, while I added a class to the whole table?

Any idea what is the correct way to achieve what I am trying to do?

Thanks a lot.

2

Your shortcode should add a unique id and not only a class. This can be an explicit id attribute (best) or by generating some random id. Now when outputting the shortcode you add a JS which uses specific selection based on the id.

  • it adds an id for the whole table, not the button, and this id is changeable based on how many tables are in the page. so If i changed the page structure, the id changes. That's what the developer told me. Here is a link to a test page. the button now has "This is my new text". I can't find a unique id for the button. Thanks – Atef Wagih Oct 15 '16 at 6:49
  • if it is not your code, then you need to ask the author to change the behaviour – Mark Kaplun Oct 15 '16 at 6:58
  • .... or you need to wrap it with your div.... write a shortcode that wraps the current one to do this – Mark Kaplun Oct 15 '16 at 6:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.