2
I wanted to know how to use my script inside the content that will be loaded by the function load()
.
The function:
$(document).ready(function() {
$('.submenu').click(function(event) {
event.preventDefault();
$('.page-wrapper').load($(this).data('href'));
});
});
The elements (sketch):
<section class="page-wrapper">
<h1> Hello, guys! </h1>
<p> Este é um exemplo do conteúdo da página </p>
<ol class="menu">
<li><a class="submenu" data-href="www.example.com" href="#">Submenu1</a></li>
<li><a class="submenu" data-href="www.example.com" href="#">Submenu2</a></li>
<li><a class="submenu" data-href="www.example.com" href="#">Submenu3</a></li>
</ol>
</section>
That is, the menu will always load via load()
. With that mine script does not work on the elements that are incorporated into my "main page". How do I fix this defect?
Phellipe, why not use bind using the function
on
? It ensures that future elements that will be added to the DOM and that satisfy this selector.– Wakim
I changed the function to
$('.submenu').on('click', function(e){...});
and the result has not changed. '-'– Phellipe Lins
Is some other fact causing this? Like the Codeigniter Framework template engine for example !?!
– Phellipe Lins
This Javascript runs on page loading, where after a while this sketch is loaded by Ajax? Tried to specify the selector better (
.submenu a
) because the selector acts on the<ul>
and not about the<a>
?– Wakim
I was wrong to do the sketch. The selector is in the right place.
– Phellipe Lins
The layout is implemented with a template engine. It is divided into
Layout.php
(footer, header and load content), Content.php (this is the content that is demonstrated in the above outline. It also loads the sidebar) &Sidebar.php
(this is the menu that contains theli
which I use as a selector.)– Phellipe Lins