asked on
$(function(){
$('a').click(function(e) {
e.preventDefault();
$(this).next('.resp').load( $(this).attr('href') );
});
function myFunction(me){
var ID = me.getAttribute("id");
var Tag = me.getAttribute("tag");
$(this).closest(".resp").html ("<p>ID " + ID + "Tag" + Tag + "</p>>");
}
});
<div>
<a id="1" href="myfile.php?param=My Word&ID=1">My Word</a>
<div id='resp_1' class='resp'></div>
<a id="2" href="myfile.php?param=MyWord&ID=2">MyWord</a>
<div id='resp_2' class='resp'></div>
</div>
<button id="Butt_1" data-tag="My Word" onclick="myFunction(this)">My Word</button>
<!-- or second URL -->
<button id="Butt_2" data-tag="MyWord" onclick="myFunction(this)">MyWord</button>
ASKER
Are you getting errors or is it just not working.Yes
<a> click is being intercepted and loaded into the next <div>The Button code is generated by PHP as a result of this click / query
ASKER
function myFunction(){
var ID = $(this).attr('id');
var Tag = $(this).attr("data-tag");
$(this).closest(".resp").html ("<p>ID " + ID + "Tag" + Tag + "</p>>");
}
ASKER
ASKER
ASKER
You need to bind the .on() to a parent element that is static
$('.content').on('click','button', function() { ...
$('.content').on('click','button .Myclass', function() { ...
$('.ButtonParent').on('click','button', function() { ...
ASKER
HTML (HyperText Markup Language) is the main markup language for creating web pages and other information to be displayed in a web browser, providing both the structure and content for what is sent from a web server through the use of tags. The current implementation of the HTML specification is HTML5.
TRUSTED BY
There are a lot of variables in this question.
For instance you have $('a').click - if you are expecting this to bind to <a> elements in the returned html it won't as it is statically bound - you would need to use .on() for that to work.
I am also not clear on the flow. I understand the first bit where the <a> click is being intercepted and loaded into the next <div> but where does the <button> code come in - is that what is being loaded into the <div> - if so what is it that is not working?