Search code examples
jquerytitle

How can I replace a href title to div


Is it possible to change a href="#" title="ooo" tag to div? i try these code but not work,

this is my Htmlcode

<ul class="test">
    <li><a href="#" class="ut" title="ok">Test1</a></li>
    <li><a href="#" class="ut" title="ok">Test2</a></li>
    <li><a href="#" class="ut" title="ok">Test3</a></li>
    <li><a href="#" class="ut" title="ok">Test4</a></li>
</ul>

Js:

$('.test').each(function(){
  var title = $(this).find(".ut a").attr("title");
  $(this).find("a div").text(title);
});

it's should be like this:

Test1

ok

Test2

ok

Test3

ok

Test4

ok

But not Work...

http://jsfiddle.net/MotoTony/UePwj/

As always, your assistance is appreciated!


Solution

  • This gives your expected output -

    http://jsfiddle.net/UePwj/7/

    $('.test a').each(function(){
        var title = $(this).attr("title");
        $(this).parent('li').append("<div>"+title+"</div>");
    });