Галерея Wordpress: Удалитьтеги с помощью jquery - PullRequest
0 голосов
/ 15 марта 2012

Я пытаюсь удалить тег <br /> из родной галереи wordpress через jquery и перепробовал много способов, но ни один из них не работает ..

Я пробовал несколько кодов ниже (примечание: я изменился вфайл моей темы <br style="clear:both" /> в <br class="clearboth" /> также я отменил регистрацию jquery и зарегистрировался в googleapis для моей темы.

<script>$('br.clearboth').html();</script>

и

<script>
(function($) {
    $.strRemove = function(theTarget, theString) {
        return $("<br/>").append(
            $(theTarget, theString).remove().end()
        ).html();
    };
})(jQuery);
</script>

Я размещаю этот код именно наначало записи div в wordpress. Может быть, я помещаю скрипт в неправильное место. Ничего не работает и ничего из этого не удаляет тег br из раздела галереи ...

Фактический исходный код, который я получаю, как показано ниже.Я пробовал js, как вы сказали, но он не работает, как вы можете видеть в исходном коде: все еще там.

<!--BEGIN: Single Post-->
    <article class="post-866 gallery type-gallery status-publish hentry mp_gallery" id="post-866">

        <div class="entry">

        <!--[this js i have added here]-->
        <script>
            $("br.clearboth").remove();
        </script>


            <style type='text/css'>
                #gallery-1 {
                    margin: auto;
                }
                #gallery-1 .gallery-item {
                    float: left;
                    margin-top: 10px;
                    text-align: center;
                    width: 33%;
                }
                #gallery-1 img {
                    border: 2px solid #cfcfcf;
                }
                #gallery-1 .gallery-caption {
                    margin-left: 0;
                }
            </style>
            <!-- see gallery_shortcode() in wp-includes/media.php -->
        <ul id='gallery-1' class='gallery galleryid-866 gallery-columns-3 gallery-size-thumbnail clearfix'><li class='gallery-item'>
                <p class='gallery-icon'>
                    <a href='http://localhost/mediatuts/wp-content/uploads/2012/03/DSC_0432.jpg' title='DSC_0432'><img width="190" height="110" src="http://localhost/mediatuts/wp-content/uploads/2012/03/DSC_0432-190x110.jpg" class="attachment-thumbnail colorbox-866" alt="Lorem ipsum dolor sit amet," title="DSC_0432" /></a>
                </p>
                    <p class='wp-caption-text gallery-caption'>

                    Lorem ipsum dolor sit amet, 
                    </p></li><li class='gallery-item'>
                <p class='gallery-icon'>
                    <a href='http://localhost/mediatuts/wp-content/uploads/2012/03/DSC_0503.jpg' title='DSC_0503'><img width="190" height="110" src="http://localhost/mediatuts/wp-content/uploads/2012/03/DSC_0503-190x110.jpg" class="attachment-thumbnail colorbox-866" alt="Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium" title="DSC_0503" /></a>
                </p>
                    <p class='wp-caption-text gallery-caption'>
                    Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium
                    </p></li><li class='gallery-item'>
                <p class='gallery-icon'>
                    <a href='http://localhost/mediatuts/wp-content/uploads/2012/03/DSC_0516.jpg' title='DSC_0516'><img width="190" height="110" src="http://localhost/mediatuts/wp-content/uploads/2012/03/DSC_0516-190x110.jpg" class="attachment-thumbnail colorbox-866" alt="DSC_0516" title="DSC_0516" /></a>

                </p></li>

                <br class="clearboth" />

                <li class='gallery-item'>
                <p class='gallery-icon'>
                    <a href='http://localhost/mediatuts/wp-content/uploads/2012/03/DSC_0657.jpg' title='DSC_0657'><img width="190" height="110" src="http://localhost/mediatuts/wp-content/uploads/2012/03/DSC_0657-190x110.jpg" class="attachment-thumbnail colorbox-866" alt="Most beautiful face evern catched before" title="DSC_0657" /></a>
                </p>
                    <p class='wp-caption-text gallery-caption'>
                    Most beautiful face evern catched before
                    </p></li><li class='gallery-item'>
                <p class='gallery-icon'>
                    <a href='http://localhost/mediatuts/wp-content/uploads/2012/03/DSC_0658.jpg' title='DSC_0658'><img width="190" height="110" src="http://localhost/mediatuts/wp-content/uploads/2012/03/DSC_0658-190x110.jpg" class="attachment-thumbnail colorbox-866" alt="Beauty queen on the earth and praising pain was born and But I must explain to you how all this" title="DSC_0658" /></a>

                </p>
                    <p class='wp-caption-text gallery-caption'>
                    Beauty queen on the earth and praising pain was born and But I must explain to you how all this
                    </p></li><li class='gallery-item'>
                <p class='gallery-icon'>
                    <a href='http://localhost/mediatuts/wp-content/uploads/2012/03/DSC_0676.jpg' title='DSC_0676'><img width="190" height="110" src="http://localhost/mediatuts/wp-content/uploads/2012/03/DSC_0676-190x110.jpg" class="attachment-thumbnail colorbox-866" alt="Handsome Guy will Look after you :)" title="DSC_0676" /></a>
                </p>
                    <p class='wp-caption-text gallery-caption'>
                    Handsome Guy will Look after you :)
                    </p></li>

                    <br class="clearboth" />

                    <li class='gallery-item'>

                <p class='gallery-icon'>
                    <a href='http://localhost/mediatuts/wp-content/uploads/2012/03/DSC_0677.jpg' title='DSC_0677'><img width="190" height="110" src="http://localhost/mediatuts/wp-content/uploads/2012/03/DSC_0677-190x110.jpg" class="attachment-thumbnail colorbox-866" alt="Dashing Guy who is looking for a gal" title="DSC_0677" /></a>
                </p>
                    <p class='wp-caption-text gallery-caption'>
                    Dashing Guy who is looking for a gal
                    </p></li><li class='gallery-item'>
                <p class='gallery-icon'>
                    <a href='http://localhost/mediatuts/wp-content/uploads/2012/03/DSC_0125.jpg' title='DSC_0125'><img width="190" height="110" src="http://localhost/mediatuts/wp-content/uploads/2012/03/DSC_0125-190x110.jpg" class="attachment-thumbnail colorbox-866" alt="DSC_0125" title="DSC_0125" /></a>
                </p></li><li class='gallery-item'>

                <p class='gallery-icon'>
                    <a href='http://localhost/mediatuts/wp-content/uploads/2012/03/DSC_0416.jpg' title='DSC_0416'><img width="190" height="110" src="http://localhost/mediatuts/wp-content/uploads/2012/03/DSC_0416-190x110.jpg" class="attachment-thumbnail colorbox-866" alt="One morning, when Gregor Samsa woke from troubled dreams, he found himself transformed in his bed into a horrible vermin." title="DSC_0416" /></a>
                </p>
                    <p class='wp-caption-text gallery-caption'>
                    One morning, when Gregor Samsa woke from troubled dreams, he found himself transformed in his bed into a horrible vermin. 
                    </p></li>

                    <br class="clearboth" />

                    <li class='gallery-item'>
                <p class='gallery-icon'>
                    <a href='http://localhost/mediatuts/wp-content/uploads/2012/03/DSC_0431.jpg' title='DSC_0431'><img width="190" height="110" src="http://localhost/mediatuts/wp-content/uploads/2012/03/DSC_0431-190x110.jpg" class="attachment-thumbnail colorbox-866" alt="DSC_0431" title="DSC_0431" /></a>
                </p></li>

                <br style='clear: both;' />
            </ul>

    </article>

    <!--END: Single Post-->

Ответы [ 2 ]

3 голосов
/ 15 марта 2012

Не очень понятно, что делает ваш код в настоящее время, но вы можете удалить br элементы из DOM следующим образом:

$('br').remove();

Вы можете настроить таргетинг на br элементов в определенном контейнере, например:

$('#container-id').find('br').remove();

Вот демоверсия: http://jsfiddle.net/YtedC/

3 голосов
/ 15 марта 2012

Если вы пытаетесь удалить теги br из DOM, вы можете сделать это:

$("br").remove();

Если вы хотите только определенного класса, сделайте это:

$("br.clearboth").remove();

Если вы хотите удалить только теги br с определенного узла, сделайте следующее:

$("#someId br.clearboth").remove();
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...