有条件地删除文本

时间:2017-05-19 11:22:01

标签: jquery

如果没有添加其他功能,是否可以删除single listings page上的其他功能文字? enter image description here

这是来自AgentPress Listings插件的PHP,它生成文本:

$output .= sprintf( '<p><b>%s</b><br /> %s</p></div>', __( 'Additional Features:', 'agentpress-listings' ), get_the_term_list( $post->ID, 'features', '', ', ', '' ) );

这是HTML输出

<b>Additional Features:</b>

这是由一个不包含过滤器的插件生成的,但我不想修改插件中的默认代码,因此不得不使用jQuery或CSS。

2 个答案:

答案 0 :(得分:1)

您可以检查兄弟姐妹的大小,然后动态删除Additional Features检查,如下所示:

if(jQuery(".property-details > .clear").find("p > b").siblings().size() > 1){
     jQuery(".property-details > .clear b").remove();
}

我提到了jQuery(".property-details > .clear").find("p > b").siblings().size() > 1,因为在这两种情况下都会呈现<br/>元素。

希望这会有所帮助。 :)

答案 1 :(得分:1)

根据您的代码,您似乎正在使用wordpress。你直接使用以下PHP代码..

<?php 
    if(get_the_term_list( $post->ID, 'features', '', ', ', '' )) {
        $output .= sprintf( '<p><b>%s</b><br /> %s</p></div>', __( 'Additional Features:', 'agentpress-listings' ), get_the_term_list( $post->ID, 'features', '', ', ', '' ) );
    }
?>
  

我们可以看到您的商品符号位于a标记中,使用jquery您可以检查它是否存在

if(!$(".property-details > .clear p a").length){
    $(".property-details > .clear p").remove();
}