hello all,
I want to use jquery to make sure that my HTML forms have the correct structure and classes.
What I want:
<form class="myclass">
<label class="label-class"><span class="there_is_supposed_to_be_a_span_here">Label</label>
<input class="input-class" type="text" />
</form>
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:
jQuery('form').addClass('myclass');
jQuery('label').addClass('label-class');
jQuery('input:text').addClass('input-class');
//now remove unwanted spans
var inp = jQuery("input");
var clean = jQuery(inp[0].outerHTML);
jQuery("span", clean).remove();
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??