SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Wizard Wolf_22's Avatar
    Join Date
    Jul 2005
    Posts
    1,700
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Finding an element within the entire HTML based off a partial wildcard string?

    I have a few input elements between multiple pages, all of which have have IDs ending in "-foobar" (preceding this is the type of content each page represents, such as a "contact_us-foobar" or "profiles-foobar", "search-foobar", etc.)

    Instead of applying individual jQuery to each exclusive element, I'd rather try to key off of each input by searching the HTML for elements that have IDs ending in "-foobar", this way I could write once but apply to many.

    Is it possible to search the entire HTML for input elements that have IDs ending in "-foobar" ?

  2. #2
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,313
    Mentioned
    178 Post(s)
    Tagged
    9 Thread(s)
    Hi there,

    Sorry for the short reply, but I am currently mobile.

    To get the elements ending in "foobar", use:

    Code JavaScript:
    $("[id$=foobar]")

    See the documentation here: http://api.jquery.com/attribute-ends-with-selector/

    If you can't get this to work, let me know and I'll knock you up an example later on.

  3. #3
    SitePoint Wizard Wolf_22's Avatar
    Join Date
    Jul 2005
    Posts
    1,700
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Worked like a charm! Thanks!

    (I started to ask you what that was but then I realized I glossed over your link. So thanks too for that link to the documentation on it. That's VERY helpful.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •