Announcement

Collapse
No announcement yet.

Remove unused section links using jquery

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Remove unused section links using jquery

    To be honest I doubt many will this useful but in the rare case ..fill your boots.

    Senario:
    I am developing a site which requires a css class applied to the last item in a 'row' (it uses <ul><li> but best described as a row so you can visualize). In my case it was <li class="last">section item</li>

    Because of this I had to set 'Column count for section lists' so every forth list item had class="last" applied to it.

    Unfortunately the downside of this fixed method is that if section list items aren't perfectly divided my column count value (4) the <ul></ul> includes a number of empty <li></li> until column count is reached.

    I'm sure a clever PHP guru can use php to do this which would be better method) but as I had jquery already on the page I included the following in the head of my outer layout:
    <script type="text/javascript">
    jQuery(document).ready(function() {
    $('li')
    .filter(function() {
    return $.trim($(this).text()) === ''
    })
    .remove()
    });
    </script>
    Basically it looks for any empty li item and strips it.
    You can modify to remove any html element you care to apply it to.

    If you aren't using jquery already you'd be bonkers to use this method as you'd be adding a large javascript library to performa simple task, maybe PHP'ers can get to work,


    Enjoy
    Bangers
    Boxhedge New Media Design
    Design and development solutions for SME's.
    Tel: 0118 966 2786
    Examples of work can be found at http://www.boxhedge.com
Working...
X