简体   繁体   中英

text inside li element

im printing out unordered lists dynamically..something like this

$sql2 = mysql_query("SELECT id, todo FROM todo");

while($row = mysql_fetch_array($sql2))
{
    $todo1 = $row["todo"];
    $todofeed.='

    <ul>
        <li>' . $todo1 . '</li>
    </ul>   

    ';
}

I want each li element that is printed out to be a link for some jQuery effect and for that I need the text inside each li element dynamically ie as and when i click on it.Any way around this?

Just add a class to your <ul> element so that you can access it with Jquery later on:

...
$todofeed.='

<ul class="effective">
    <li>' . $todo1 . '</li>
...

With Jquery manipulate the DOM so that your link is added:

$('ul.effective li').wrapInner('<a ... />');

But you could also add the click/hover events on the li elements. Do what suits you better, your question is not really specific, so hopefully this will give you some ideas.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM