Javascript jQuery获取id和类中的所有内容
我需要一种方法来搜索和获取id=“mydata”和class=“myheader”之后的所有内容 因此:Javascript jQuery获取id和类中的所有内容,javascript,jquery,Javascript,Jquery,我需要一种方法来搜索和获取id=“mydata”和class=“myheader”之后的所有内容 因此: 函数findit(){ var str=`Get allthiscontent`; console.log(str); } 因此,在这种情况下,str需要返回: <p>Get all <strong>this</strong> content</p> 获取所有此内容 我如何才能做到这一点?我会将其转换为html并以这种方式获取数据,因此:
函数findit(){
var str=`Get allthiscontent`;
console.log(str);
}
因此,在这种情况下,str需要返回:
<p>Get all <strong>this</strong> content</p>
获取所有此内容
我如何才能做到这一点?我会将其转换为html并以这种方式获取数据,因此:
函数findit(){
设tmpDiv=document.createElement('div')
tmpDiv.innerHTML=`获取所有此内容内容`
让myHeader=tmpDiv.querySelector(“#mydata.myHeader”)
log(myHeader.innerHTML)
}
findit()
将html字符串包装在$()
中,并像在dom中一样对其使用jQuery方法
函数findit(){
var str=`Get allthiscontent`;
console.log($(str).filter('#mydata').find('.myheader').html());
}
findit()
$('.myheader').text()
?我需要首先查找#mydata。。。然后在那里查找.myheader,因为html$(“#mydata”)中有多个myheader.find(“.myheader”).text()
。或者$('#mydata')。查找('.myheader').html()
。
<p>Get all <strong>this</strong> content</p>