I have this scenario.
In my HTML
page, when click on an a
element, I load some HTML
and jQuery
content as string, and change a div
's content (via innerHTML
) to this new text.
Here is the jQuery
code:
<script type="text/javascript">
$("a.accessor").click(function(event) {
var cId = this.id;
$.get("/video/" + cId)
.done(function(data){
var contentDiv = document.getElementById("navigator");
contentDiv.innerHTML = data;
})
.fail(function(data) {
alert("An error occured during request. Please try again later!");
});
});
</script>
The problem is that after this jQuery
code runs, the new jQuery
code (that replace this one), does not respond.
Bellow is the new HTML/jQuery
code that I get:
<div class="breadcrumb">
<a href="/video">Competitors</a>
<span>></span>
<a href="#">Name</a>
</div>
<div class="video-browser">
@for(v <- competitor.getVideos()) {
<div class="folder">
<a id="@(competitor.getId())_@v.getId()" class="accessor">
<img src="@routes.Assets.at("images/movie_file.png")" />
<span>@v.getVideoName()</span>
</a>
</div>
}
<script type="text/javascript">
$("a.accessor").click(function(event) {
alert(123);
});
</script>
Obs. I put some code related to my framework that I use for the sake of conciseness.
Having the HTML/jQuery
above, when I try to click on an a
element I get nothing. Can anybody explain me why this?
If you need more details, ask me for, please.
Thanks in advance!