how to use javascript in html
<!-- include an external javascript document -->
<script src="myJavaScript.js" charset="utf-8"></script>
<!-- JavaScript inside html element -->
<script>
console.log("This is JavaScript");
</script>
how to use javascript in html
<!-- include an external javascript document -->
<script src="myJavaScript.js" charset="utf-8"></script>
<!-- JavaScript inside html element -->
<script>
console.log("This is JavaScript");
</script>
script js
<script type="text/javascript" src="monscript.js"></script>
js script
<script src="javascript.js"></script>
script tag in html
<script>
// Write JS here
</script>
<script src="link/to/js/file.js"></script>
SCRIPT.JS
$(document).ready(function(){
// When user clicks on submit comment to add comment under post
$(document).on('click', '#submit_comment', function(e) {
e.preventDefault();
var comment_text = $('#comment_text').val();
var url = $('#comment_form').attr('action');
// Stop executing if not value is entered
if (comment_text === "" ) return;
$.ajax({
url: url,
type: "POST",
data: {
comment_text: comment_text,
comment_posted: 1
},
success: function(data){
var response = JSON.parse(data);
if (data === "error") {
alert('There was an error adding comment. Please try again');
} else {
$('#comments-wrapper').prepend(response.comment)
$('#comments_count').text(response.comments_count);
$('#comment_text').val('');
}
}
});
});
// When user clicks on submit reply to add reply under comment
$(document).on('click', '.reply-btn', function(e){
e.preventDefault();
// Get the comment id from the reply button's data-id attribute
var comment_id = $(this).data('id');
// show/hide the appropriate reply form (from the reply-btn (this), go to the parent element (comment-details)
// and then its siblings which is a form element with id comment_reply_form_ + comment_id)
$(this).parent().siblings('form#comment_reply_form_' + comment_id).toggle(500);
$(document).on('click', '.submit-reply', function(e){
e.preventDefault();
// elements
var reply_textarea = $(this).siblings('textarea'); // reply textarea element
var reply_text = $(this).siblings('textarea').val();
var url = $(this).parent().attr('action');
$.ajax({
url: url,
type: "POST",
data: {
comment_id: comment_id,
reply_text: reply_text,
reply_posted: 1
},
success: function(data){
if (data === "error") {
alert('There was an error adding reply. Please try again');
} else {
$('.replies_wrapper_' + comment_id).append(data);
reply_textarea.val('');
}
}
});
});
});
});
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us