<div class="ptp-item-container">
<div class="plan">New Text to Display!</div>
<div class="price">200</div>
<div class="bullet-item">some other text</div>
<div class="cta"> <a class="button" href="javascript:getText()">Go!</a>
</div>
</div>
When I clicked the button, I experimented with this code:
function getText(){
alert($(this).parent().parent().children().text() );
}
Unfortunately, it didn't give the desired outcome and I'm aware that a solution exists using $(this) for this task.
Update: Below is the entire Javascript code:
<script>
jQuery(document).ready(function($) {
$(".ptp-button").attr("href", "javascript:getText()");
});
function getText(){
alert($(this).closest('.ptp-item-container').find('.plan').text());
}
</script>
Upon inspection, the console displayed an error message "Uncaught TypeError: undefined is not a function VM4092:1(anonymous function)"
Should I pass $(this) as an argument in javascript:getText($(this)) or something similar?