A Stupid JavaScript Problem

I’ve been struggling with one simple JavaScript problem tonight.

You see, I’ve got this div, which has any number of child elements (div’s). Each child element is named row_#, with a unique #, based on the database entry it was generated from (the auto-inc’ing key field).

So I want to figure out what the very last element name in that list is (ie: row_208), and get just the numerical portion of it (so I end up with just 208), so I know what to update from (thereby only pulling the needed records out of the database, rather than doing a total refresh).

Sounds simple, doesn’t it? Unfortunately, I can’t get back a string, all I can get back is a reference to the DOM element. Can anyone help me out here? It’s probably something simple, I’m just not Googling the right words, but at this point I’m too tired to think…

June 19, 2006 at 6:23pm | 1 Comment
Tagged: , , , , and 

1 Comments so far

  1. Chris Meller, on June 20, 2006 at 8:27pm, said:

    I still can’t believe I was that stupid, but here’s the solution for anyone else who might be as naive as I was last night…

    // create your object, could be any number of ways. // the key is that eventually you have an object that is your div obj = getElementById('moo'); // or $('moo') if you're cool like that theID = obj.id; // theID will be 'moo', in case you didn't guess that already

    That’s it. Instead of obj.name or obj.value, you just do obj.id, which gets the ID attribute of the object. Apparently last night I’d forgotten that once you have the object, it really has nothing to do with the ID. You’re just using the ID as a pointer to initially find the object you’re later referencing. The object still has an ID attribute, just like it has a name or value attribute (depending on the type of element).

    Ok, my stupid moment is over… Move along.

    Edit Comment

Leave a Comment?


« Playing Over at WordPress.Com  —  My Night Off »

Recent Comments

Monthly Archives

More...

Tags

More...