Book a Free Call

JQuery id starts with selector



This is a handy way to target any element with a common string in the id.

$('[id^="yourstring-"]').on('touchstart click', function(e){ e.stopPropagation(); e.preventDefault(); console.log(this); }); };

an element with id=”yourstring-whatever” would be targeted this way.

It does seem a little intensive on the DOM so maybe whittle down the elements to target it inside a container, thereby letting the browser know that it doesn’t have to go through the whole page, just to a container wherein it will find all the ids it might be looking for

Something like $(‘.yourcontainer [id^=”yourstring-“]’)

Anyway, enjoy!

Need rapid website development:

For smaller projects at high speed


  • Adding script tag embed to Gatsby component

    Read More
  • Get more than 100 queries in GraphQL (I felt stupid)

    Read More
  • Animate on Scroll (AOS) into Nuxt js

    Read More
  • WordPress Super-admin hack

    Read More
  • Add content or ACF field under thumbnail/image gallery in Woocommerce

    Read More

Tags


Categories

Is it urgent? Donate to Cork Simon

Got an urgent issue?

Charlie's Cottage, Carrigrohane, Co. Cork, T12 WY9H

(085) 7686677