My current init() code targets element IDs starting at ‘desc_1′,’desc_2’,’desc_3’…and so on.
function init(){
var max = 50000;
for (i = 1; i < max; i++){
makeEditable('desc_'+i);}
}
Most of the elements on a page won’t actually start at 1. For example, they might be ‘desc_47′,’desc_48′,’desc_49’ – or in some cases, aren’t even sequential: ‘desc_96′,’desc_99′,’desc_101’.
What would my init() statement have to be to target these types of element IDs?
Thanks in advance!
Instead of guessing at 50000 IDs, just select all elements that have an ID starting with
desc_, then pass the element tomakeEditable().If they’re all the same element type, replace
*in the selector with the tag name.If there are other elements that start with that ID, then assign a class to the elements so you can target them directly.
If you can’t add a class, then before passing it, you’d just need to test the
idof each element to make sure it has a number at the end.