Break first word with jQuery

    [javascript]
    <!DOCTYPE html>
    <head>
    <title>Break first word with jQuery</title>
    <style type="text/css">
    .firstWord {display: block;}
    li {float: left; margin: 0 5px;}
    </style>
    <script type="text/javascript">
    $(‘ul.nav > li > a’).each(function() {
    var obj = $(this);
    var text = obj.html();
    var parts = text.split(‘ ‘);
    var replace = ‘<span class="firstWord">’+parts[0]+'</span>’;
    parts.shift();
    $.each(parts, function(key, value) {
    replace += ‘ ‘+value;
    });
    obj.html(replace);
    });
    </script>
    </head>
    <body>
    <ul class="nav">
    <li><a href="#">Local Issues</a></li>
    <li><a href="#">Have Your Say</a></li>
    <li><a href="#">Public Newsroom</a></li>
    <li><a href="#">Join The Team</a></li>
    </ul>
    </body>
    </html>
    [/javascript]

    Leave a Reply