I have for example a <div id="main"></div> and inside this div tag I load html content from extrernal file using jquery with .load() method. I can see evething has loaded normaly inside this div tag, but can not access any html tag loaded from the external html via css or jquery. Any advice would be very usefull. Thank you!

2 Years
Discussion Span
Last Post by romanromeo89

sounds like the issue is related to the fact that you added data after the fact using ajax...

For example, you wouldnt be able to attach the click event using .click() because the elements havent been loaded yet. You would use the .on() method.. for example..

$('#divId).on('click', 'targetElement', function()....

What this does that that any targetElement added to the divId element will have the click() bound to it, even if the elements come in after the fact via ajax.

We really need to see your sample code, but thought this may put you on the right path in the meantime.


Thank for help,
I actually have this index file:

<?php ?>

<title>Med Manager</title>
<link rel="stylesheet" type="text/css" href="style/main.css">

    <div id="main_container">
        <div id="left_sidebar">
            <div id="add">           
                <button onclick="load_add_new_supplier()">Add supplier</button>
        <div id="container"> 
            top menu

            <main id="main">

    <script type="text/javascript" src="js/jquery-1.10.2.min.js"></script>
    <script type="text/javascript" src="js/ajax.js"></script>


A button call function load_add_new_supplier(), stored in file ajax.js

ajax.js file:

function load_add_new_supplier(){

And this function loads this content, view-ajax_add_new_supplier.php :

<form name="ajaxform" id="ajaxform" action="model-ajax_add_new_supplier.php" method="POST">
        <td><input type="text" name="afm"></td> 
        <td><input type="text" name="type"></td> 
        <td><input type="text" name="name"></td> 
        <td><input type="text" name="address"></td> 
        <td><input type="text" name="phone"></td> 
        <td><input type="text" name="fax"></td> 
        <td><input type="text" name="comments"></td> 
    <button id="add_button" onclick="sendform()" type="button">add</button>

which is a simple form. It works as I want. But I didn't manage to access any tag loaded from model-ajax_add_new_supplier.php neither with jquery selector or with css.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.