javascript - Applying a style to and inserting a line break after the first word in a link -


I have been asked to recreate an HTML site in WordPress and all I have done is that one Manny has done in addition to the bar. See the image on this:

In short, I want a method of styling the first word of an element differently and insert line break after its first word. I'm sure this is a quick jquery hack, but it's not enough info about JQ to be with your own.

Here's the catch: A drop-down menu appears with those small arrows, I have a dropdown function, but to ensure that whatever solution applies on the main menu, with dropdowns ( They leave the ul list within the LI item).

Any help would be appreciated.

Without an HTML example of your menu, it is difficult to give you a specific answer.

But you can use some jQuery as the following, this will allow you to add the word to the first word, and all else it is .split () in the html , Will give you an array. Wrap the first item into the span allowing the style, then uses jQuery .each () to add the loop back to the string through the rest. After this HTML has been replaced with the new version:

  $ ('# header> gt; ul.nav & gt; li & gt; a'). Each (function () {var obj = $ (this); var text = obj.html (); var parts = text.split (''); var = '& lt; span class = "first ward" & gt; '+ Parts [0] +' ; Br / & gt; 'parts.shift (); $ .eich (parts, function (key, value) {change + =' '+ value ;}); Obj.html (change);});   

Example CSS:

 . FirstWorld {font-size: 15px; } .menuHeader {margin-left: 10px; Swim left; Font-size: 40px; }. Menu {width: 100%; Height: 120px; Background color: #ff 8c 00;   

A


Reflect the code from the comment.

Use selector:

  $ ('# header> gt; ul.nav & gt; li & gt; a')   

You only need to add the first menu item to select:

 . First World {font-size: 15px; }   

To adjust the size of the first item to your CSS. Good suggestions by


, you can change jQuery: gt = ul.nav & gt; li & gt; a' Text.split (''); var = '& lt; span class = "firstword" & gt;' + parts [0] + '<-span>
parts.shift (); + = Parts.join (' '); obj.html (replaced);});

To make it a little smaller.

Comments

Popular posts from this blog

qt - switch/case statement in C++ with a QString type -

python - sqlite3.OperationalError: near "REFERENCES": syntax error - foreign key creating -

Python's equivalent for Ruby's define_method? -