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

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

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!

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

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)
seconds ago
a minute ago
minutes ago
an hour ago
hours ago
a day ago
days ago
Invalid characters found