I'm working on a form where I want to change an input's type jQuery, and thanks to this wonderful website I've already found out that I need to clone and replace the input to change the type. The problem I've run into is I added a variable and when I run the code it just doesn't work, it does work though when I use the ID of the input instead of the variable. Code is below.
These are the variables:
var productOne = $j("#ninja_forms_field_25");
var productOneDiv = $j("#ninja_forms_field_25_div_wrap");
This code doesn't work:
$j(".button1").click(function() {
$j(productOneDiv).css("height", "37px");
$j(productOne).clone().attr({
"type": "text",
"placeholder": "Product"
}).insertAfter(productOne).prev().remove();
});
This is the code that works:
$j(".button1").click(function() {
$j("#ninja_forms_field_25_div_wrap").css("height", "37px");
$j("#ninja_forms_field_25").clone().attr({
"type": "text",
"placeholder": "Product"
}).insertAfter("#ninja_forms_field_25").prev().remove();
});
I've searched for solutions and really couldn't find anything useful.