Search code examples
phpjqueryconcrete5

removing redundant HTML code from page using jQuery or PHP?


I have some code in my Concrete5 template which i dont need if the user has not uploaded gallery images. I therefore need to remove the following code IF it contains no images:

<ul class="Gal_2">
       <li class="Frst">    
       </li>

       <li>
       </li>
</ul>

It looks like this when it has images in:

<ul class="Gal_2">
    <li class="Frst">
        <p><a rel="group" href="/concrete/files/2113/6352/1788/Lighthouse.jpg"><img width="1024" height="768" alt="Lighthouse.jpg" src="/concrete/files/2113/6352/1788/Lighthouse.jpg"></a>
        </p>
    </li>
    <li>
        <p><a rel="group" href="/concrete/concrete/themes/greek_yogurt/Images/TEMP_IMG1.jpg"><img width="800" height="537" alt="Island Rab" src="/concrete/concrete/themes/greek_yogurt/Images/TEMP_IMG1.jpg" style="float: left;"></a>
        </p>
    </li>
</ul>

What would be the fastest way to check and remove the markup?


Solution

  • Try using :not and :has

    Live Demo

    $('.Gal_2:not(:has(a))').remove();