Search code examples
css-selectorscasperjsselectors-api

CasperJS querySelectorAll id start with specific string


How do I get all the DIVs starting with ID div-gpt-ad?

This is the line

document.querySelectorAll('div#div-gpt-ad-1363287890054-0-oop');

there are multiple divs with IDs starting with div-gpt-ad on my page and I want to get them all.


Solution

  • document.querySelectorAll('div[id^=div-gpt-ad]');
    

    This will get all div tags with an id starting with div-gpt-ad.