Pop Up only responds to first Element

I have my pop up set to Element ID = Quote

On the page I have several buttons that contain the ID = Quote

The pop up only responds to the first instance of the Element ID (Button). Others down the page don’t activate the pop up.

How can I get all of the buttons to make the pop up activate?

Hi there, @Mark_Farrow and welcome to the Community :waving_hand:

I’ve checked your website and see that only one more button has id"Quote":


There is another Get a Quote button on the page, but it doesn’t have ID “Quote”:


Would you like both buttons to trigger the popup, or only the button from the 1st screenshot?

Sure its here: https://forestpest.wpenginepowered.com/

First Button on the page is “Get an Instant Quote”
Going down the page the next button is “Get a Quote”
Third Button is “Get a Free Quote”
4th Button is “Get a Quote”

I have all of their Element ID’s set to “Quote”

OK I just corrected that, and I do want all of the buttons to activate the POP UP. I also want to use this same technique on inner pages.

Got it, thanks!

I’ve forwarded your request to the dev team and will let you know once the solution is ready :slightly_smiling_face:

And the final question: should the Get a Quote button in the form also trigger the popup?

Thank you.

@Mark_Farrow Could you just answer the question about the Get a Quote buttons in the forms (my previous message)?

No, the forms are a separate function. Using Formidable forms Plugin…

Got it, thanks!

I’ll keep you updated :slightly_smiling_face:

Hi @Mark_Farrow :waving_hand:

Thank you for waiting!

Here is a custom script from our devs:

<script>
  document.addEventListener('DOMContentLoaded', () => {
    const TARGET_BUTTON_NAMES = [
      'Get a Quote',
      'Get Instant Quote',
      'Get a Free Quote'
    ];

    function normalizedString(str) {
      return str.toLowerCase().trim();
    }

    function compareButtonText(text) {
      return TARGET_BUTTON_NAMES.map(normalizedString).includes(
        normalizedString(text)
      );
    }

    const buttons = Array.from(
      document.querySelectorAll('a[role="button"][class*="nectar-button"]')
    ).filter(({ textContent }) => compareButtonText(textContent));

    buttons.forEach((button) => {
      button.addEventListener('click', (e) => {
        e.preventDefault();
      });

      button.setAttribute('id', 'Quote');
    });
  });
</script>

Please add right after the widget’s installation code and let me know how it worked :slightly_smiling_face:

This version doesnt work it only works on the first button in the homepage other buttons don’t activate the pop up.

this version sent yesterday at 7am works:

<script>
const TEXT = 'quote';

const waitForElements = (selector, root = document) =>
	new Promise((res) => {
		const observer = new MutationObserver(() => {
			const elements = root.querySelectorAll(selector);
			if (elements.length) {
				res(elements);
				observer.disconnect();
			}
		});

		observer.observe(root, { childList: true, subtree: true });
	});

waitForElements('a[role="button"]').then((buttons) => {
	buttons.forEach((button) => {
		const buttonText = button.querySelector('span')?.textContent;

		if (!buttonText) return;

		if (buttonText?.toLowerCase()?.includes(TEXT)) {
			const triggerButton = document.querySelector('#Quote');

			if (!triggerButton) return;

			button.addEventListener('click', (e) => {
				e.preventDefault();
				e.stopPropagation();

				triggerButton.click();
			});
		}
	});
});
</script>

Now this one isn’t working for all buttons either…

I am so sorry about that!

I’ll double-check this solution with the devs and will get back to you once I have any news :slightly_smiling_face:

Actually the initial version does work, sorry about miscommunication.

Oh, that’s great!

If anything else comes up, we’ll be delighted to help :wink: