I am sorry that I found what I did wrongly.. just typal mistake between the html file and txt file
First of all, I apologies to my poor English.
I am trying to get the html code inside a div
in the external txt file dynamically through ajax by jQuery. However, I cannot get the html code in specific div
as I expected.
Here comes my code
.html file
<div id="html_div_id_A">
<div class="html_div_class">
</div>
</div>
<div id="html_div_id_B">
<div class="html_div_class">
</div>
</div>
abc.txt file
<div id = "txt_div_id_A">
<div class="txt_div_class">
some content A
</div>
</div>
<div id = "txt_div_id_B">
<div class="txt_div_class">
some content B
</div>
</div>
.js file
function func(arg)
{
var htmlDivId = $(arg).attr("id").toString()// html_div_id_A or html_div_id_B, decided in run time
var txtDivId = htmlDivId == "html_div_id_A" ? "#txt_div_id_A" : "#txt_div_id_B";// txt_div_id_A or txt_div_id_B, decided in run time
// What I could do now
$(htmlDivId + " > .html_div_class").load("abc.txt #txt_id_B div");
// What I expected to do
$(htmlDivId + " > .html_div_class").load("abc.txt " + txtDivId + " div");
}
I have tried the solution that suggest in here (Use Jquery Selectors on $.AJAX loaded HTML?) but it does not work. Are there any way to solve this problem?