How to get the value of the Title of clicked button in Adobe Launch?

399 Views Asked by At

I would like to use the custom code of Data Elements in Adobe Launch to get a text value for the parent element of the clicked element.

I used $('h2.cmp-teaser__title.wow.animated').text(); method,

When i click the button:("a.cmp-teaser__action-link") it should get the value of the title("cmp-teaser__title.wow.animated") but when I checked with debug tool, the text value is not collected properly. Custom Code of Data Elements in Adobe Launch

My Code for reference:

<div class="cmp-teaser__content">
        <div class="cmp-teaser__pretitle">Feature Title</div>        
    <div class="cmp-teaser__title wow animated" style="visibility: visible;">
        <h2>Broclux Title</h2>
    </div>
    <div class="cmp-teaser__description">
        <p>Sample text Sample text Sample text Sample text</p>
    </div>        
    <div class="cmp-teaser__action-container">        
    <a class="cmp-teaser__action-link" href="#.html" target="_self" title="">View Collection</a>
 </div>
2

There are 2 best solutions below

0
On

The css selector is incorrect. The h2 is inside of the div.

You'll want this:

$('div.cmp-teaser__title.wow.animated > h2').text()
0
On

You'll need to use this. And please avoid jquery.

Your dataelement should just return this.parentElement.parentElement.querySelector("h2").innerText