1
votes

I would like to get innertext of an a element with condition.

<a href="www.url.com">text</a>

The condition a would like to set is to find innertext of an a element on which the href value start with a certain text.

For example following my example i would like to get output = text for href start with 'www'.

1
Please post any attempt you have made. - Ryan Wilson

1 Answers

0
votes

I think you're looking for

document.querySelector('a[href^=www]')

The snippet above will query the entire document looking for a elements that have a href attribute with a value starting with www

Have a look here for querySelector and here for possible attribute selectors