Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6014205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:39:30+00:00 2026-05-23T02:39:30+00:00

I have elements in my DOM with class=LiveVal:variablepart and i would like to write

  • 0

I have elements in my DOM with class=”LiveVal:variablepart” and i would like to write a JQuery selector that works even if the elements have other classes on tom of the above. Eg. class=”header LiveVal:varablepart” or class=”LiveVal:varablepart header”.

It works fro me if LiveVal is the first class with:

$('[class^=LiveVal:]').each(function ( intIndex ) { somefunction });

but obviously not if another class is before LiveVal.

In the function I need to extract the variable part. I planned to do like this:

theclass = $( this ).attr('class');
varpart = theclass.replace('\bLiveVal:(.+?)[\s]', '$1');

..but alas, it doesn’t match. I’ve tested the regex on http://gskinner.com/RegExr/ where it seems to work, but it doesn’t in javascript !?

Any help would be greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T02:39:31+00:00Added an answer on May 23, 2026 at 2:39 am

    It might be somewhat faster to do this with an explicit filter:

     $("*").filter(function() { return /\bLiveVal:/.test(this.className); }).something();
    

    It depends on whether the native “querySelectorAll” does the work, and does it quickly. This also would avoid the “FooLiveVal” problem.

    It’s worth noting that in an HTML5 world, it might be better to use a “data-LiveVal” attribute to store that “variable part” information on your elements. Then you could just say:

    $('[data-LiveVal]').something();
    

    In the HTML, it’d look like this:

    <div class='whatever' data-LiveVal='variable part'>
    

    Since version 1.5, jQuery will fetch stuff in a “data-foo” attribute when you pass the tail of the attribute (the part after “data-“) to the “.data()” method:

      var variablePart = $(this).data('LiveVal');
    

    The “.data()” method will not, however, update the “data-foo” property when you store a new “variable part”.

    edit — if you want the value that’s stuffed into the class after your property name prefix (“LivaVal:”), you can extract it like this:

      var rLiveVal = /\bLiveVal:(\S*)\b/;
      $('*').filter(function() { return rLiveVal.test(this.className); }).each(function() {
        var variablePart = rLiveVal.exec(this.className)[1];
        //
        // ... do something ...
        //
      });
    

    (or some variation on that theme).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have several common elements (components), that will generate some html. it seems my
I have several identical elements with different attributes that I'm accessing with SimpleXML: <data>
I have a bunch of input elements that have a particular substring in their
I'm trying to do the following: I have two sets of DOM elements on
I have a web app where I have several elements with class=classA . I
Often times I have elements hooked to added functionality, like: $('.myfav').autocomplete(); $('.myfav').datepicker(); $('.myfav').click(somefunction); But
Have some simple jquery that Im trying to execute on a button click. For
I have two elements: <input a> <input b onclick=...> When b is clicked, I
I have some elements on a page which are draggable. These same elements have
I have two elements (a button and an anchor tag) both with a dynamical

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.