I'm sure a lot of you have come across this dilemma at one time or another:
I have a block-level HTML element that contains multiple block-level and inline-level elements, e.g.
<div id="ajax">
<h2>Something</h2>
<div class="icon"></div>
<div class="clear"></div>
<div class="somethingelse"><h3>blah</h3></div>
</div>
I simply want to attach a jQuery ajax() event to a click on #ajax (the top-level element), but I need to pass through a few parameters to the server-side script.
One possible way I'm seeing is simply replacing div#ajax
with a#ajax
, which would allow me to add something like href="param=value&this=that"
, but this would render the page invalid: there can't be any block-level elements (<div>
) inside of an inline element (<a>
).
Another possible way would be adding a rel
attribute to div#ajax
, which would also mean neglecting XHTML validation.
I don't want to go adding inline onclick
events to divs, that's a little too far out... Also, turning all children of div#ajax
into e.g. <span>
would be a major pita.
How would you handle this?
Thanks!