It gets the first part of a div id with '_' as delimiter. The problem is that an id cannot start with a number (naming violation convention). So I am going to add a letter before the id value in my php script. How do I insert substr(1) to this var to remove this letter and get 'average' as expected?

I might prefer to do it like this so it's a little less presumptious about the exact format and just grabs the first floating point numeric sequence:

var average = parseFloat(this.id.match(/[\d\.\+\-]+/)[0]);

Also, notice how I removed the jQuery. $(this).attr("id") performs a lot worse than this.id and offers no advantages here. jQuery should be used only when it's actually better than plain JS.

Both of these methods assume you are only going to present the code with properly formatted ids. If you want to handle a default condition when the id is not in the right format, then you will need multiple lines of code with some if conditions to check for validity and offer a default result when not valid.

I could not get it work. The script is from myjqueryplugins.com/jRating It gets from<div id="3.5_5634"></div> the average rating 3.5 of the item #5634. I added a "W" so id="W3.5_5634"> and then changed the JS line but the result wasn't correct
–
dstonekApr 12 '12 at 2:11

@dstonek - The concept works as shown here: jsfiddle.net/jfriend00/B4Rga so you'll have to show your whole code for us to know why it doesn't work for you.
–
jfriend00Apr 12 '12 at 2:24

@dstonek - I added a third option to my answer that might be even better.
–
jfriend00Apr 12 '12 at 2:46

Very nice, the first one works as expected. My dumb fault: I had changed the original JS but while the script loads the minified version. Now I go to test your last suggestion. Many thanks.
–
dstonekApr 12 '12 at 19:33