Reputation: 2035
The jQuery code:
jQuery.get(templateDir + "/file.php",function(data){
var content = jQuery(data).filter('#content').text();
console.log(content);
jQuery("#id").hide().html(content).fadeIn(1000);
},"html");
The html structure:
<p id="content">content here</p>
<p id="content2">another content here </p
etc....
What I'm trying to do is get the inner text/html of the p#content
element.
I found some solutions online but nothing seems to work.
I tried find()
and filter()
as suggested in most, but they didn't solve my problem.
jQuery(data).text()
works by the way.
What'd be a way to do it then?
Upvotes: 0
Views: 527
Reputation: 518
you could try jquery each $("#testp p[id='content']").each...
,check this jsfiddle xtc, it has a wrapper element and one with no wrapper.
EDIT:
Ok so if its coming back as a string, doesn't this example work, cos the html string is being assigned to a variable "testelement" like the variable "content" in your above question?
EDIT: CODE-EDIT 2:
var testelement='<p id="notcontent">Hello</p><p id="content" >content hello</p>';
//old version--> $(testelement).each(function()
$(testelement).find('p').each(function() //new version
{
if($(this).is("p") && this.id=='content')
{
alert($(this).text());
alert($(this).html());
}
})
Upvotes: 1