1

I am appending anchor tag from jquery. While clicking on this anchor tag, does nothing. I triedd by changing anchor to div and added onclick event too. But it is not working.

Html:

    <li class="list">
        <div class="dropdown" data-load="true">
        <span class="dropdown-toggle"></span>
            <ul class="dropdown-menu" role="menu">
                <li>
                    <span class="list-name" href="javascript:void(0);">
                        test
                    </span>
                </li>
            </ul>
        </div>
    </li>

Script:

    var element = $(".list").find("ul");
    var options = "";
    options += "<li><a class='list-name' href='www.test.com' target='_blank' data-toggle='tooltip' data-placement='top' data-original-title=''>" + "some value" + "</a></li>";
    element.html(options);

Output:

    <li class="list">
        <div class="dropdown" data-load="true">
        <span class="dropdown-toggle"></span>
            <ul class="dropdown-menu" role="menu">
                <li>
                    <a class="list-name" href="www.test.com" target='_blank' data-toggle="tooltip" data-placement="top" data-original-title="">some value</a>
                </li>
            </ul>
        </div>
    </li>
3
  • 1
    You are missing the protocol. eg. https:// or http://
    – Turnip
    Jul 3, 2017 at 9:53
  • What do you mean with "it's not working" what does not work? like if you put quotes around "some value" it does work: jsfiddle.net/yk154x7p doesn't it ?
    – caramba
    Jul 3, 2017 at 9:59
  • Sorry for the confusion. I have double quotes around "some value". I have edited now. Still anchor tag is not working.
    – D Aon
    Jul 3, 2017 at 10:06

1 Answer 1

0

https://jsfiddle.net/anubala/kpgfgt74/

 var options = "";

options = "<li><a class='list-name' href='www.test.com' target='_blank' data-toggle='tooltip' data-placement='top' data-original-title=''>" + "some value" + "</a></li>";

$(".list").find("ul").html(options);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.