Now that we've learned the basics of writing and testing jQuery selectors, we'll learn how to apply jQuery to identify an element for a SmartTip in the Editor.
Generally, this process has 4 steps:
- Identify/Inspect the element.
- Write the jQuery selector.
- Test the jQuery selector.
- Implement the jQuery selector in the Editor.
Let's review this process with an example scenario on the Eddie's Depot site.
Scenario |
---|
Recall from Builder I when we created a couple of Guidance SmartTips. Now the Eddie's Team is coming to us since they've pinpointed that their Enter a promo code SmartTip isn't being found consistently on the page. To fix this, they'd like to instead use jQuery to identify the element. ![]() |
Step 1 - Inspect the element |
---|
First, let's start by inspecting the Enter a promo code element. Go to the Eddie's Cart page, right click the element, then click Inspect.![]() |
Step 2 - Write the jQuery selector |
---|
Now, we can see the element in the HTML. The HTML that is highlighted and corresponds to the Enter a promo code element is: <span id="coupon-label" data-hook="Coupon.ShowButtonText">Enter a promo code</span> Based off what we've learned so far, we should identify the element using its id because ids are unique to the page and are quick for WalkMe to find from a performance perspective. *jQuery selector revealed in the next step so you can test yourself*![]() |
Step 3 - Test your selector |
---|
The selector we've chosen to identify the element is #coupon-label(span#coupon-label also works!) To make sure this selector is correct and unique to the page, we'll test our selector in the Console. Move to the Console tab and enter the following: wmjQuery("id="coupon-label")Then, press Enter. If you've written a unique selector for the page, you should see length: 1 return in the results meaning only one element was found. In addition, when you hover the highlighted selector (as shown in the screenshot), the element's location will also highlight on the page. ![]() |
Step 4 - Add the jQuery to the step |
---|
In the Editor, select the Enter a promo code SmartTip, then navigate to the Selected Element tab. In the Define how to identify the element section, select JQuery selector. Then enter the selector into the field. Click Done, then Save. ![]() |
Summary |
---|
Now that we've added a jQuery selector to identify the element, you can Play or Preview the step from the Editor to make sure the element is found consistently on the page. When making changes to real content, you'll also want to Publish the updated content to your environment(s). |