Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/406.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jQuery获取id和类中的所有内容_Javascript_Jquery - Fatal编程技术网

Javascript jQuery获取id和类中的所有内容

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并以这种方式获取数据,因此:

我需要一种方法来搜索和获取id=“mydata”和class=“myheader”之后的所有内容

因此:

函数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>