jQuery toggleClass example
Toggle class name on click in jQuery
by veer_vin
HTML
<div id="banner-message">
<p>Hello World</p>
<img src="https://zohodiscussions.com/getCustomFile.do?fileId=14737000008150849&forumGroupId=14737000000003003" alt="jakecigar" forumid="14737000000003006" purpose="authorProfile" authorid="2950240" authorname="jakecigar">
<button>Submit</button>
<input type="file" id="fileCheck">
</div>
CSS
body {
background: #20262E;
padding: 20px;
font-family: Helvetica;
}
#banner-message {
background: #fff;
border-radius: 4px;
padding: 20px;
font-size: 25px;
text-align: center;
transition: all 0.2s;
margin: 0 auto;
width: 300px;
}
#banner-message img {
width: 100%;
}
button {
background: #0084ff;
border: none;
border-radius: 5px;
padding: 8px 14px;
font-size: 15px;
color: #fff;
}
#banner-message.alt {
background: #0084ff;
color: #fff;
margin-top: 40px;
width: 200px;
}
#banner-message.alt button {
background: #fff;
color: #000;
}
JavaScript
// find elements
var banner = $("#banner-message")
var button = $("button")
// handle click and add class
button.on("click", () => {
var formData = new FormData(); // Currently empty
formData.append('username', 'Chris');
formData.append('username', $("#fileCheck").val());
formData.append('userimage', '<img src="https://zohodiscussions.com/getCustomFile.do?fileId=14737000008150849&forumGroupId=14737000000003003" alt="jakecigar" forumid="14737000000003006" purpose="authorProfile" authorid="2950240" authorname="jakecigar">');
formData.append('userHtml', '<div><img src="https://zohodiscussions.com/getCustomFile.do?fileId=14737000008150849&forumGroupId=14737000000003003" alt="jakecigar" forumid="14737000000003006" purpose="authorProfile" authorid="2950240" authorname="jakecigar"><h2>What is Lorem Ipsum?</h2><p><strong>Lorem Ipsum</strong> is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\'s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p></div>');
formData.append('realHtml', $("#banner-message").html());
$.ajax({
type: "POST",
enctype: 'multipart/form-data',
url: "https://reqres.in/api/users",
data: formData,
processData: false,
contentType: false,
cache: false,
success: function(response){
console.log(response);
}
});
})