how to select content/text only, without the tag?

Anne-Catherine wambersie Jan 15, 2015 04:00AM PST

Hi,
I want to select only the TEXT inside this span without the <a>, seems obvious but i am missing something:
<span class="example"><a href="#">TEXT</a><span>

if I select .example a => <a href="#">TEXT</a>

I just want TEXT as a result.

Thanks for your help,

anne-Catherine Wambersie

Up 0 rated Down
Stewart Yu Jan 15, 2015 09:47AM PST Mobify Agent

Hi Anne-Catherine,

Great question! Using “CSS Match”, we always select on full HTML elements. But, if you choose “JavaScript Match”, you can write a function to return the text instead. It might look something like this:

function() {
return $(‘.example a’).text();
}

Hope this helps!
Stewart

Up 0 rated Down
Anne-Catherine wambersie Jan 16, 2015 03:12AM PST
Thanks, but if I enter this

function(){
return $(‘.ancestors a’).text();
}

into the selection rectangle, clicking Javascript select,

it returns:
syntax error line2 , unexpected token illegal
Up 0 rated Down
Stewart Yu Jan 16, 2015 09:09AM PST Mobify Agent

Hi Anne-Catherine,

I think the issue is with smart quotes. Can you try deleting and re-typing the quotes around: .ancestors a

Once we have regular quotes, instead of smart quotes, this should work properly.

Hope this helps!

Post Your Public Answer

Your name (required)
Your email address (required)
Answer (required)
support@mobify.me
https://cdn.desk.com/
mobify
Loading
seconds ago
a minute ago
minutes ago
an hour ago
hours ago
a day ago
days ago
about
Invalid characters found
/customer/en/portal/articles/autocomplete