0

I have an unordered list

<ul id="List1">
    <li>www.xyz.com</li>
    <li>www.abc.com</li>
</ul>

using jquery, I want to convert this li to a link and add font as underline

I am trying it like this

$('li').css('font', 'underline').click(function () {
    // how to add hyperlink?
});
ankitkanojia
  • 3,072
  • 4
  • 22
  • 35

2 Answers2

2

What about something like this? This will turn the elements into actual links, so you don't need to add the underline or onclick handler.

    $('li').each(function(e) {
        $(this).wrapInner('<a href="http://' + $(this).text() + '"></a>');
    });

In your example, the list items were urls, so this will only work if that remains the case.

Charles
  • 539
  • 1
  • 3
  • 11
  • Links are normally underlined by default - so unless you've changed the default style to remove the underlining, that code should result in underlined, clickable links. – Charles May 11 '09 at 03:32
  • Ok i used text-decoration and it happened. How can i add two css attributes at the same time..for eg: text-decoration and color to the
  • tag
  • –  May 11 '09 at 03:32
  • You can use this syntax: $('li a').css({ "text-decoration": "underline", "color": "#333333" }); If you're changing several CSS attributes, though, I'd usually make a new class and then assign the class to the links. – Charles May 11 '09 at 03:37