So a few weeks ago someone asked about adding little icons to menu items. You responded with the clever little idea of adding some HTML in an unusual place:
Quote:
Yes you can add code into the menu name to call up an image.
In the page settings go to the Menu Text box and instead of "Home" you can place a small image after the word Home with the code below.
Code:
Home<img src="images/yourimage.png" align="absbottom"hspace="5" border="0px">
I thought this was pretty darn nifty. But I couldn't get it to work for me. XSP chewed it to pieces on me; it turned the above HTML into:
Home<img src="images/yourimage.png" align="absbottom"hspace="5" border="0px">
which didn't work worth a darn, I can tell you.
So I went a little further around the barn and, in the Other->Global Scripts->In the HEAD section of the page tab I put:
Code:
<script type ="text/javascript" src="http://code.jquery.com/jquery-1.7.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("a.mainlinksINFO_BAR_MENU").append("<img src=\"images/alongtheway.png\" align=\"absbottom\" hspace=\"5\" border=\"0px\">");
})
</script>
The first line brings jQuery facilities into your web page from a CDN without having to download it ner nothin'. It's just right there, right now.
The "$(document).ready(function()" bit causes the script to execute when the DOM is done building but before the page is complete (before graphics and suchlike are all done).
The jQuery line attaches the image to ALL your menu items...even ones you add later.
The naughty bits you have to change to make this work on YOUR page are:
alongtheway.png - this has to be changed to YOUR image which you've loaded into the Resource Manager.
mainlinksINFO_BAR_MENU - this is the XSP assigned class for your menu. You will need to examine the output page code for the page your menu is on. Look right before any one of the menu items and you should find the equivalent entry for you to use.
Had it worked for me, the advantage/disadvantage (depending on your perspective) of your approach was it's simplicity and the fact that you could have a different graphic for each menu item. You CAN accomplish the same thing with MY method, but you'd have to use a slightly different jQuery selector and a similar statement for each one.
My technique does change all the menu items at once (in this example) to use the same graphic, all with one statement. AND it does open the door to changing ANY of the HTML ANYWHERE to more suit personal whim. AND you can fiddle with the CSS as well. With a little effort, you can get your paws on anything with this approach.
Any idea why your technique didn't work for me?