I am trying to cut down on some very repetitive code and below is an example, but its not working, I cant work it out how to use var id in $(id) if its possible anyway.
var greenTick = $(id).closest('.card').find('.greenTick').css({ "display": "inline" });
if (testEmail.test($('#txtEmailAddress').val().trim()))
{
var id = '#txtEmailAddress';
greenTick;
}
greenTick basically needs to have the value of id pushed into it, is it possible?
var greenTick = $(id).closest('#cardAdministrator').find('.greenTick').css({ "display": "inline" });
if (testEmail.test($('#txtEmailAddress').val().trim()))
{
var id = '#txtEmailAddress';
greenTick;
}
var greenTick = $(id).closest('#cardAdministrator').find('.greenTick').css({ "display": "inline" });
if (testEmail.test($('#txtEmailAddress').val().trim()))
to
var greenTick = $(id).closest('#cardAdministrator').find('.greenTick').css({ "display": "inline" });
console.log(id)
if (testEmail.test($('#txtEmailAddress').val().trim()))
var greenTick = $(id).closest('#cardAdministrator').find('.greenTick').css({ "display": "inline" });
if (testEmail.test($('#txtEmailAddress').val().trim()))
{
var id = '#txtEmailAddress';
greenTick;
console.log(id);
}
So then I changed it to this, and got a Object {length …
var id = '#txtEmailAddress';
greenTick;
console.log(greenTick);
This gives me undefined
var greenTick = $(id).closest('#cardAdministrator').find('.greenTick').css({ "display": "inline" });
console.log(id);