TipsOnLips.net

Your .net tips and tricks source

About the author

Author Name is someone.
E-mail me Send mail

Recent comments

Authors

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2010


Wrap an li element with an Anchor (link) element using JQuery

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

    <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />

    <title>Untitled 1</title>

 

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>

 

    <script type="text/javascript">

        $(function() {

        var firstLi = $('li:first');

 

        var anchor = '<a href="javascript:void(0)" onclick="myclick(\'' + firstLi.text() + '\')"></a>';

        firstLi.wrap(anchor);

        });

 

        function myclick(test) {

            alert(test);

        }

    </script>

 

</head>

<body>

    <ul id="myUL">

        <li>Dav Letterman</li>

    </ul>

</body>

</html>


Categories: JavaScript | Jquery
Posted by developer on Wednesday, December 09, 2009 1:15 AM
Permalink | Comments (0) | Post RSSRSS comment feed

Add comment


(Will show your Gravatar icon)

  Country flag


Loading