-2

I have 2 elements:

<p id="mdn-slice-product-page-display">3 makset 10€ kuus, ilma lisatasudeta. </p>
<p id="mdn-slice-product-page-display">Järelmaks alates 0.98€ / kuu, 0€ lepingutasu. </p>

Created by the same plugin on the same line, so I don't want to edit the plugin.

I found a solution to replace the text in the first one:

jQuery("#mdn-slice-product-page-display").text(jQuery("#mdn-slice-product-page-display").text().replace("makset", "payments"));
jQuery("#mdn-slice-product-page-display").text(jQuery("#mdn-slice-product-page-display").text().replace("kuus, ilma lisatasudeta", "per month, no extra cost"));

I have no idea how to target the second one. This will have to do until the developer fixes their plugin only, so does just need to work.

CD7
  • 7
  • 3
  • 1
    "*[Multiple] elements with the same ID...*" - this, right here, is the problem; an `id` must be unique within the document; this is true regardless of your desires regarding changing/updating the plugin. Have you looked at the plugin to ensure that it can't generate unique `id` attributes, or use classes instead? – David Thomas Dec 06 '22 at 14:58
  • I edited the plugin to add a class to these, so I can target those now I guess. Sadly the jQuery does not seem to work. Oh well. One thing at a time. – CD7 Dec 06 '22 at 15:18

1 Answers1

0

You can't do that. An id has to be unique.

You either need to make the ids of each item unique, or use class like so:

<p class="mdn-slice-product-page-display">3 makset 10€ kuus, ilma lisatasudeta. </p>

The elements are then targeted by:

".mdn-slice-product-page-display"

And then you must loop over the array found like so:

[/* your jQuery object*/].forEach(item => {
  // do stuff
})
Harrison
  • 1,654
  • 6
  • 11
  • 19