tags:

views:

178

answers:

2

I have a 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?
            });
A: 

You should check out the "linkify" method mentioned in this question: http://stackoverflow.com/questions/247479/jquery-text-to-link-script/248901#248901

tester
+2  A: 

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
thanks..how can I underline it
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
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 <li> tag
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
thanks buddy for all the help!