I want to use jquery to make sure that my HTML forms have the correct structure and classes.
What I want:
<label class="label-class"><span class="there_is_supposed_to_be_a_span_here">Label</label>
<input class="input-class" type="text" />
So I want to use jquery to add the classes to the elements and also to remove any unwanted spans.
This is what I have so far:
//now remove unwanted spans
var inp = jQuery("input");
var clean = jQuery(inp.outerHTML);
Only problem is that my remove code gets rid of all spans! - I only want to remove spans that are wrapping the inputs or the labels - but I need to leave the span nested inside the label.
How can I do this??
Erm, not 100% sure what you are trying to achieve.
So some labels and inputs are wrapped in spans and some are not? You want to find the ones that are and remove the spans? Is that correct?
How about putting the relavent html into a variable and removing the spans using a regex? Then appending the variable data to the DOM?