0

I have an add button,on click of that an input field must be appended.Instead of input,if I place <p> in append(),it is appending.Where I am going wrong ?

HTML

<div id="inputstack">
<input type="text" class="selector" value="new">
<input type="text" class="selector" value="old">
<input type="text" class="selector" value="newest">
<input type="text" class="selector" value="oldest">
<input type="text" class="selector" value="older">
</div>
<input type="button" value="Add" id="addinput" />

JavaScript

$('.selector').on('blur',function () {
 var current_value = $(this).val();
 $(this).attr('value',current_value);
console.log(current_value);
 if ($('.selector[value="' + current_value + '"]').not($(this)).length > 0 || current_value.length == 0 ) {
 $(this).focus();
 alert('You cannot use this');
 }
});
$('#addinput').click(function(){
$('#inputstack').append("<input type="text" class="selector" value="">");
});

My fiddle is here

asked Dec 10, 2015 at 10:24

2 Answers 2

1

syntax error .. please keep eye on console .. quotes problem

$('#inputstack').append('<input type="text" class="selector" value="">');

Working Demo

answered Dec 10, 2015 at 10:25
Sign up to request clarification or add additional context in comments.

1 Comment

@IamRaviteja never mind its always happening when you spend more time in coding .. Good Luck :)
0

Just change the double quotes to single quotes like this:

$('#addinput').click(function(){
 $('#inputstack').append('<input type="text" class="selector" value="">');
});
answered Dec 10, 2015 at 10:26

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.