First of all, I apologize for my poor English.
I'm using jquery plugin jParse which parse xml easily. here is the demo page(http://jparse.kylerush.net/demo)
I've tried a couple times but can't seem to figure out how to remove <a>
tag if the href is empty.
Here is my code:
elementTag: ['category'开发者_开发问答, 'pubDate', 'title', 'link', 'description'];
output: '<dl><dt class="jpet00">jpet01</dt><dd><strong><a href="jpet03">jpet02</a></strong><br />jpet04</dd></dl>';
if the xml 'link' node is empty, i want to output like this
output: '<dl><dt class="jpet00">jpet01</dt><dd><strong>jpet03jpet02</strong><br />jpet04</dd></dl>';
I tried $("a[href='']").remove() but it didn't work.
Are there any suggestions? Thanks in advance!
Where are you calling $("a[href='']").remove()
- it should be in your finish()
function shown in the demo. If this is where you are using it it may be that the href is not entirely empty. Try:
function finish() {
jQuery('#jparse-meta').remove();
$('a').each(function() {
var string = $(this).text().replace(/\s{2,}/g, '')
if (string == "") {
$(this).remove();
}
});
}
EDIT 1 as requested in comments
function finish() {
jQuery('#jparse-meta').remove();
$('a[href=""]').each(function() {
$(this).parent('strong').html($(this).text());
});
}
I didn't test, but something like it might do the job:
$("a").each( function() {
if($(this)).text= "") {
$(this).remove();
}
}
)
精彩评论