[英]Get all the content within <style> tag in a html file using jquery
[英]using jquery to get the content of a <tag>
我有一個關於“未知”標簽的問題。 我的意思是HTML中沒有定義的標簽。
請參閱以下塊:
<div class='container'>
<element definition>
</div>
然后使用jquery我想得到所有div的孩子的列表,然后提取他們的內容。 為了實現這一點,我不知道我是否只有RegExp,或者有一些jQuery函數可以獲得。
例如,定義一個將標簽更改為<p>
的函數set_tags_to_p()
。
您可以使用p
非常簡單地替換子元素,如下所示:
$('.container').children().replaceWith(function() {
return '<p>' + $(this).html() + '</p>';
});
$('.container').find('*').each(function () {
$(this).replaceWith('<p>' + $(this).html() + '</p>')
})
你可以做這樣的事情
var element, elementHtml, pTag;
element = $("element") // you can change the name
elementHtml = element.html();
pTag = $("<p>").html(elementHtml);
如果您知道要替換的標記的名稱,則可以執行以下操作:
<div class="container">
<up>Test</up>
<down>Test</down>
<left>Test</left>
<right>Test</right>
<broken>Test</broken>
</div>
$(function(){
$('.container').children("up, down").replaceWith(function() {
return '<p>' + $(this).html() + '</p>';
});
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.