Hello, I have all the countries within the tag select. How to change the attribute id and inserting a corresponding value? <option value="1" id="">Afghanistan</option> <option value="2" id="">Albania</option> <option value="3" id="">Algeria</option> Code (markup): Еxactly what I would like to receive: <option value="1" id="1">Afghanistan</option> <option value="2" id="2">Albania</option> <option value="3" id="3">Algeria</option> Code (markup): Thanks!
1) why would you be putting ID's on options in the first place? Only legitimate reason to be targeting them scripting-side would work off the parent SELECT... and it's not like they are valid targets for CSS (even if firefox lets you do so) 2) It's invalid to start an ID with a number. 3) Why would you be post-processing with regex instead of just handling it in the output 4) wouldn't it be better to have meaningful values like say... the two digit region codes, or omit value altogether so it passes something meaningful like the country name? Not sure what you are doing, but not sure why you'd have that be anything more than: <option>Afghanistan</option> <option>Albania</option> <option>Algeria</option> Code (markup): Only reason to have ID on an option is... uhm well there's... uhm... and if you omit value it will pass something far, FAR more useful... like the data inside the OPTION. Then you don't need any post-processing nonsense with regex or so forth. ... and even if you did, I'm not sure why you'd use a regex to insert them instead of just having it there in your template or equivalent in the first place.