Reputation:
I have a question regarding "unknown" tags. I mean tags that are not defined in HTML.
See the following block:
<div class='container'>
<element definition>
</div>
And then using jquery I want to get the list of all div's children and then extract their content. To achieve this, I don't know if I have only RegExp to do, or there are some jQuery functions to get.
For instance, defining a function set_tags_to_p()
that changes the tags to <p>
.
Upvotes: 0
Views: 67
Reputation: 1638
If you know the name of the tags you want to replace, you could just do:
<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>';
});
});
Upvotes: 0
Reputation: 207900
$('.container').find('*').each(function () {
$(this).replaceWith('<p>' + $(this).html() + '</p>')
})
Upvotes: 1
Reputation: 9692
You can do something like this
var element, elementHtml, pTag;
element = $("element") // you can change the name
elementHtml = element.html();
pTag = $("<p>").html(elementHtml);
Upvotes: 0
Reputation: 193271
You can replace children elements with p
pretty easy like this:
$('.container').children().replaceWith(function() {
return '<p>' + $(this).html() + '</p>';
});
Upvotes: 1