简体   繁体   中英

JQuery Toggle class selects all text

I currently have a small tab on the side of the screen that when clicked toggleClass is called to make the div larger. At the same time there is an ajax call to populate the larger div with content. What happens though is that all of the text within the div gets selected/highlighted as if I were to drag my mouse across the whole thing.

Is there a way to have it not be selected, or at least de-select it after it has loaded?

Here is the code:

   $(".summary-box-small").click(function () {

        $("#summary-box-container").toggleClass('summary-box-small summary-box-full', 1000);
        $.ajax({
            url: '/RuntimeSession/LoadSummaryBox',
            type: 'post',
            success: function (data) {
                $("#summary-box-container").empty().append(data);

                $("#sb-content").tabs();
                $("#tree").dynatree({
                    onActivate: function (node) {
                        alert("You activated " + node);
                    }
                });
            }
        });

        $(".summary-box-small").off('click');   //turns off the click handler so when it is expanding clicking anywhere will not make it minimized
    })

And here is the css:

.summary-box-small
{
    position: fixed;
    top: 400px;
    left: 0px;
    z-index: 9999;
    height: 70px;
    width: 20px;
    background-color: #cfcfcf;
}

.summary-box-full
{
    position: fixed;
    top: 400px;
    left: 0px;
    z-index: 9999;
    height: 500px;
    width: 350px;
    background-color: #cfcfcf;
    opacity: 0.9;
}

Here is the content being loaded by the AJAX call:

    <div id="sb-header">
    <p style="float: right">X</p>
</div>
<div id="sb-content">
    <ul>
        <li><a href="#sb-nav">Nav</a></li>
        <li><a href="#sb-dx">Dx Tracker</a></li>
    </ul>

    <div id="sb-nav">

        <p>fake content under the nav...MAKE ME A GORRAM TREE</p>
         <div id="tree">
        <ul>
            <li id="key1" title="Look, a tool tip!">item1 with key and tooltip</li>
            <li id="key2" class="selected">item2: selected on init</li>
            <li id="key3" class="folder">Folder with some children</li>
            <li id="key4" class="expanded">Document with some children (expanded on init)</li>
            <li id="key5" class="lazy folder">Lazy folder</li>
        </ul>
    </div>
    </div>
    <div id="sb-dx">
        <p>fake content</p>
    </div>
</div>

$(".summary-box-small").click()事件之外添加以下内容是否有作用?

$("#summary-box-container").disableSelection();

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