No Line Break With jQuery .append()

时间秒杀一切 提交于 2019-12-13 03:18:52

问题


I'm parsing a XML using jQuery with the following code:

function appendNav(xml) {
    $(xml).find("Nav").each(function() {
        $("#navBar").append("<a id='navItem' href='" + $(this).find("Link").text() + "'>" + $(this).attr("name") + "</a>");
        $("#navBar").append("<div class='navItemSep'> | </div>");
    });

    $(".navItemSep").filter(":last").remove();
}

And using the following XML:

<Navbar>
    <Nav name="Home">
        <Link>index.html</Link>
    </Nav>
    <Nav name="Twitter">
        <Link>http://twitter.com/nathanpc</Link>
    </Nav>
</Navbar>

The problem is that I'm getting this on multiple lines instead of only a single one. What I need to do to make it output this on a single line?


回答1:


Try changing the div to a span



来源:https://stackoverflow.com/questions/6481941/no-line-break-with-jquery-append

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!