OptinMonster Documentation

Documentation, Reference Materials, and Tutorials for OptinMonster

Home

Docs

How to Use OptinMonster’s HTML Element Targeting Rule

How to Use OptinMonster’s HTML Element Targeting Rule

OptinMonster makes it easy to hide or show campaigns based on an HTML element in the page the campaign is loading on.

In this article, you’ll learn how to use OptinMonster’s Display Rules to hide or show a campaign based on an HTML element.

Before you start, this feature requires a Growth subscription.

This rule can only target an element that already exists on your website.

Configure HTML Element Rule

When you create a campaign in OptinMonster you can configure it to be shown or hidden based on an HTML element in the page.

To configure the HTML element rule, follow these steps:

  1. Navigate to the Display Rules view in the campaign builder.
    Navigate to the Display Rules in the OptinMonster campaign builder.
  2. Next, when adding or editing a rule select Who (Personalization) from the left-hand list and select the HTML Element Targeting option.
    HTML Element Targeting in OptinMonster.
  3. Configure the rule as desired using the operator dropdown and text field.
    Configure the HTML Element rule in OptinMonster.
    The following options are available for HTML Element Targeting:
    • matches selector
    • does not match selector
    • is visible, and matches selector
  4. When you’re finished, Save the campaign.

Examples

The following examples are to help you get started:

Exactly Matches Selector

If you wanted to check for an HTML element with an ID of testHTMLelementID, you would enter #testHTMLelementID as the value, as shown below.

HTML Element example.
Does Not Exactly Match Selector

If you wanted to only show the campaign when a certain element does NOT exist on the page, you can use the does not match selector operator. Since the value of the input can be any valid query selector, you can be quite creative with this rule.

In this example, we’ll only show the campaign when a certain HTML element does not exist on the page. Using the does not match operator, we’ll check if an element with the ID of testID that is a child of any element with a class name of className exists on the page.

If any elements matching this query are found on the page, the campaign will not display.

HTML Element example.

FAQs

Can I learn more about how this Display Rule works?

You can enter a key (matches selector or does not match selector) to search for in the page source.

OptinMonster then uses document.querySelector to search for whatever string you’ve entered in the Display Rule. If that string is or is not found, depending on the selected operator, the campaign will show.

This Display Rule is especially helpful for more technical users since you can set up your own conditions using custom Javascript or HTML and then only display the campaign if that HTML element is detected.

How does the “is visible and matches selector” operator work?

When using this rule it will check your query selector and then determine if the targeted element exists.

If the element exists, it will then determine if the element is visible to the visitor.

If the element is hidden, or the visitor hasn’t scrolled down enough to see it yet, the campaign will not display.

Once the visitor has scrolled to the targeted element, or the targeted element otherwise becomes visible in the visitor’s viewport, the campaign will display.


If you’re serious about jumpstarting your website business growth, then get started with OptinMonster today!

Get Started With OptinMonster Today!

BONUS: Done-For-You Campaign Setup ($297 value)

Our conversion experts will design 1 free campaign for you to get maximum results – absolutely FREE!

Click here to get started →


Still stuck?

How can we help?

Last updated on


Start Getting More
Leads & Sales Today
with OptinMonster!

Create and launch smart capture forms today in minutes. What are you waiting for?

Create and launch smart capture forms
today in minutes. What are you waiting for?

OptinMonster has transformed our business. Before integrating their optins, our clients saw a 2% conversion rate from web traffic, which is slightly above the standard for their industry. With the integration of OptinMonster’s lightbox popup, exit-intent technology, split testing, and other tools, our client’s conversion rates soared by an unprecedented 500%. They attracted substantially more customers while spending less on digital advertising. Their success propelled them to the top of their markets, outperforming national chains and other medical spas with much bigger marketing budgets. Our client’s success in their market has distinguished us in our own. We are now one of the most sought-after marketing firms in the industry of aesthetic medicine. We know that the integration of OptinMonster, more than any other tool or marketing strategy, has supported this growth and achievement.

chris zelig medstar media

Chris Zelig

Partner, Medstar Media

OptinMonster has been a game-changer for us. From driving donations to collecting new leads, there is nothing that this simple tool has failed to accomplish. Our lead collection rate has jumped by over 1,000%.

joe lowe american bird conservancy

Joe Lowe

Director of Digital Communications, American Bird Conservancy

Through OptinMonster’s exit-intent popups, we have more than doubled our sales conversion rate. Best of all is the compound effect of using OptinMonster over a long period of time—more conversions mean more customers, which means more word of mouth.

mitch smith, managing director, shockbyte

Mitch Smith

Managing Director, Shockbyte.com