Search code examples
jquerydomjquery-validation-engine

Create a div before another


I have a script from a JQuery Validation Engine. I want to set the prompt div before another div.

if($('#'+methods._getClassName(field.attr("id"))+'_msddHolder').length ){
var prompt = $('<div>');
$('#'+methods._getClassName(field.attr("id"))+'_msddHolder').before(prompt);
prompt.addClass(methods._getClassName(field.attr("id")) + "formError");
// add a class name to identify the parent form of the prompt
prompt.addClass("parentForm"+methods._getClassName(field.closest('form, .validationEngineContainer').attr("id")));
prompt.addClass("formError");

If I do it like this it won't work, if i manually set this:

$('#'+methods._getClassName(field.attr("id"))+'_msddHolder').before('<div>TEST</div>');

Then it works. Why?


Solution

  • You apply class after your before method. The class won't apply then on your element. Have you tried :

    var prompt = $('<div><h4>I am a test</h4></div>');
    $('#'+methods._getClassName(field.attr("id"))+'_msddHolder').before(prompt);
    

    Just to see if you have an element insered ?