I want to add a transparent input text field in the centre of DIV #mainC
each time the button is clicked.
I tried doing this with jquery but did not succeed.
I want to add a transparent input text field in the centre of DIV #mainC
each time the button is clicked.
I tried doing this with jquery but did not succeed.
use append()
:
$("#abc").click(function() {
$("#main").append('<input type="text" />');
});
Well there's multiple things wrong with your code:
$('<input type="aText" id="aText">').appendTo('#main')
is not a valid jQuery, instead try to use: $('#main').append('<input type="text" id="aText">');
aText
is not a valid input type attribute valueThere is no library selected at the upper left corner in jsfiddle. Try to select jquery there.
Use append()
and try not to specify onclick
inline. You can register the event with jQuery when document is ready. Registering methods this way is preferred because you separate logic from your HTML (Check unobtrusive javascript).
This is how you would do it preferably:
$('#abc').on('click', function(){
$('#mainC').append('<input type="aText" id="aText">')
})
Check also jsfiddle
The problem you had with your jsFiddle was also that no jQuery script was selected.