Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

(Simple) Are HTML attributes allowed to have spaces between assignments

I'm doing some attribute parsing as a string, so I need to know how spaces are used in HTML/XHTML element attributes:

  <div id='myid' width='150px' />

Is this also correct?

  <div id = 'myid' width = '150px' />

If anyone knows other ways of iterating through attributes and their values using JavaScript, I'd be interested to know.

like image 725
Robin Rodricks Avatar asked May 06 '09 06:05

Robin Rodricks


2 Answers

Yes, both are correct. Rather than string parsing, you'll want to use the DOM. Check out jquery.

like image 147
Al W Avatar answered Sep 18 '22 01:09

Al W


The spaces are allowed. If you are parsing attributes why don't you let the browser parse? If you are using innerHTML than you get elements that have an attribute list

like image 40
Norbert Hartl Avatar answered Sep 22 '22 01:09

Norbert Hartl