2

I need to attach string html to the DOM using jQuery:

I have this HTML string:

 var html = "<div id="inspectorMenu" style="display: none;">"+
            "<label id="showInspectorName"  style="padding: 13px 09px; color:white"></label>"+
            "<ul id="" class="nav pull-left">"+
            "<li style="display: inline-block;text-align: center; max-height:35px;"><a class="navbar-brand" ui-sref="sites.list" style="padding: 11px 09px;" title="אתרים"><i class="glyphicon glyphicon-tree-conifer"></i></a></li>"+
            "<li style="display: inline-block;text-align: center;max-height:35px;"><a class="navbar-brand" ui-sref="sitesDamages.sitesList" style="padding: 11px 09px;" title="אירועים"><i class="glyphicon glyphicon-exclamation-sign"></i></a></li>"+
            "</ul>"+
            "</div>"

And I have this html code:

    <div class="navbar-header">
        <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
        </button>
        @Html.ActionLink("sites maintaice", "Index", "Dashboard", new { area = "" }, new { @class = "navbar-brand" })

  //===========I need to add html string here!!!==============//

    </div>

Using jQuery I need to add html string between </div> tag and @Html.ActionLink .

Any idea how can I implement it?

1
  • Give your navbar-header an ID, then do document.getElementById(id).innerHTML += yourHTML; ? Commented Nov 5, 2016 at 19:24

1 Answer 1

2

To insert the HTML after the markup generated by @Html.ActionLink, at the end of the DIV, you can append

$(".navbar-header").append(html);
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for the answer. What if I need to remove at some point the added html?
@Michael you should add Id to that element (to that html) and then i.e. $('#thatGivenId').remove() or $('#thatGivenId').hide()

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.