kisiel kisiel - 1 year ago 65
HTML Question

'Close' button does not work in javascript

In the mobile version on my form appears 'Close' button.
Unfortunately, it does not work. I see a normal button, but when I click there is no reaction. In the javascript I load the file form-with-button.html to render form content in my all .html files.

<div id="form-with-button">

and use javascript to show and close.

//Onload show header and footer content
$("#header").load('header.html', function(){
offset: {top: $('#header').height()-$('#nav').height()}


// Sticky Buttons Show Hide
$("#fix-quote, #fix-contact").on("click", function() {
var body = $("body");
var openPos= ["",""];
var id = $(this).attr("id");
var content = $("#"+id+"-content");
var property = (content.attr("class").toString().indexOf("left") > -1)? "left": "right";
if (!body.hasClass("bd_"+id)) {
openPos= [0,380]
var ele = $(this);
body.on("click.fix",function(ev) {
if($(".fixed-container").length == 0){
} else {

content.css("top","").show().css(property, openPos[0]);
$(this).css(property, openPos[1]);

// Mobile Requests Showhide
$("#fix-quote-mob, #fix-contact-mob").on("click", function() {
var id = $(this).attr("id").slice(0,-4);
var content = $("#"+id+"-content");
$(".fix-contact-close").on("click", function() {
var content = $(this).closest(".fixed-container");


Please help, why my button does not work?

Answer Source

You are trying to add a handler to an element created in a dynamic way, so you need to refactor your code in order to make it work:

 $(document).on("click", ".fix-contact-close" function() {
     var content = $(this).closest(".fixed-container");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download