1
I’m a beginner when it comes to Javascript and jQuery and I’m trying to create a dynamic div, my goal is to create an Alert bootstrap whenever the button is pressed but I’m not getting it to happen...
<button id="myBtn">Click Here</button>
This is the script:
$("#myBtn").click(function() {
$(this).after(
'<div class="alert alert-success alert-dismissable">'+
'<button type="button" class="close" ' +
'data-dismiss="alert" aria-hidden="true">' +
'×' +
'</button>' +
'Password Changed' +
'</div>');
});
And how do I change the contents of this Div or the innerHTML I suppose?
– Afonso
you can pass variables inside the values of the attributes, an example would be: Let meuValor = 'value1' $('<div>', { html: meuValor, }). appendTo('body');
– Hiury B. Bressanelli
I didn’t understand what you meant by passing variables into the attributes, could I explain otherwise please?
– Afonso
Of course. We will solve your problem of creating an Alert: first you create the div with Jquery: Let minhaDiv = $('<div>'); then you add a content to it, your bootstraps classes: myDiv.addClass('Alert Alert-Success Alert-dismissable'); , and you play that div created into somewhere, right? can be body: myDiv.appendTo('body'); If you want to create an input and put inside that div, it’s the same process, but you put an appendchild(); http://api.jquery.com/ndappend/
– Hiury B. Bressanelli
Thank you very much for the explanation but I have one more question, how do I put a text like "Password Changed" that I have in my example? Thank you :)
– Afonso
in Jquery, if you use . html('text in here') to write something in the label style or description of a button, Voce would make your $('<button>'). html('text of the button');
– Hiury B. Bressanelli