It would be easier to use the built-in options and let the plugin create your span elements. The end result of the generated HTML will be what you request.
JQuery
$(document).ready(function () { $('#signUpForm').validate({ // initialize the plugin errorElement: 'span', errorClass: 'help-inline', rules: { company: "required", username: "required" }, messages: { company: "Required !", username: "Required !" } }); });
HTML
<form id="signUpForm"> <div class="control-group"> <label class="control-label" for="inputCompanyName">Company Name</label> <div class="controls"> <input name="company" type="text" id="inputCompanyName" placeholder="" /> </div> </div> <div class="control-group"> <label class="control-label" for="inputFirst">User Name</label> <div class="controls"> <input name="username" type="text" id="username" placeholder="" /> </div> </div> <input type="submit" /> </form>
DEMO: http://jsfiddle.net/eRZFp/
BTW . The User Name field is missing the attribute name , name="username" . For this plugin to work correctly, all input elements must contain a unique name attribute.
source share