Button doesn't work inside div, but works outside

Button doesn't work inside div, but works outside

Hi guys and thanks in advance for your help.

Hi guys and thanks in advance for your help.

I'm quite inexperienced with Ajax and I have been having a problem with something I have been trying to do. Its a basic notifications container using <div> and some other elements.

Problem is, I can't seem to get any buttons to work inside the div. My latest attempt is a 'Mark All Read' button at the bottom, using ajax, calling a php file (currently only has an echo for testing).

Any ideas on what i'm missing?

This is the button line, which sits inside another container for the notifications.

<div id="markallread" class="markAll">
    <input type="button" id="markallr" value="Mark All as Read" class="button">
</div>

And the ajax I have:

$(document).ready(function () {
    $("#markallr").click(function () {
        $.ajax({
            url : '../markread.php',
            type : 'POST',
            success : function () {  
                alert ("YES");
            },
            error : function () {
                alert ("NO");
            }
        });
    });
});

PHP file, like I have said is just an echo for testing.

<?php echo "Success"; ?>

Now, I can place the button at the top of the page, outside of the container, and it gives me the Alert 'Yes' but doesn't run the php file. Soon as I place it anywhere in the container, I lose all function.

php html ajax

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Know Everything About HTML With HTML Experts

HTML Assignment Help Australia @30% OFF from Sample Assignment, with Our Best HTML assignment help experts. Get HTML homework help online at affordable price. 100% Plag free assignment solution.

Commonly Used HTML Tags with Examples

HTML tags are keywords used in HTML to display web-pages with certain properties. They are further used for defining HTML elements. An HTML element consists of a starting tag.

Hire Dedicated PHP Developer

Looking to hire affordable yet experienced PHP developers? **[Hire Dedicated PHP Developer](https://hourlydeveloper.io/hire-dedicated-php-developer/ "Hire Dedicated PHP Developer")**, who can convert your idea to reality, within the stipulated...

All You Need To Know About HTML Forms

This article provides an introduction to styling forms with CSS, including all the basics you might need to know for basic styling tasks.

How to Include PHP in HTML

Welcome to this article on how to use PHP in HTML! Here, we try to get specific about exactly how PHP and HTML interact, at the level of a specific .php file. In other words, how do you actually include PHP in HTML, and what rules can and can’t you follow in weaving PHP and HTML together?