0👍
✅
wrap the code in $(document).ready()
method. ex,
$(document).ready(function(){
$('#add_more').click(function() {
alert('click');
});
});
the functions inside .ready()
method initializes when the whole document is ready.
👤Raab
1👍
You should always use the jQuery ready function to ensure the document is loaded before the code is executed. Eg:
$(function() {
$('#add_more').click(function() {
alert('click');
});
});
- [Answer]-Using Django REST Framework API for data model with composite key
- [Answer]-Why is django not showing the content what I declare in template?
- [Answer]-Groups for M2M object based permissions
0👍
You might need to wrap that in this:
$(document).ready(function () {
$('#add_more').click(function() {
alert('click');
});
});
👤xivo
- [Answer]-Alternative to global variables in Django?
- [Answer]-SelectMultipleHelpTextRemovalMixin yields "Cannot create a consistent method resolution"
0👍
1) your second script is loading before the DOM. You need to use document.ready
$(document).ready(function(){
$('#add_more').click(function() {
alert('click');
});
});
2) another option is to move
<script>
$('#add_more').click(function() {
alert('click');
});
</script>
below
<input type="button" value="Button 2" id="add_more">
- [Answer]-Django restful framework's request.user has two different type and different value?
- [Answer]-Django inlineformset_factory with predefined modelchoice field rendered as text
- [Answer]-Conditional field and formsets
Source:stackexchange.com