简体   繁体   中英

Selecting text in a popup box using Jquery

I have a button. When i click that button, a popup CSS box appears having a text field which has some data. I want this data to be selected as soon as the popup box opens. I tried using the .select() function in jquery but it doesn't seem to be working.

This is the button :-

<div id="copyBox" style="display:inline-block; margin-left: 10px;"> 
    <button class="btn copy-button"  id="obj" data-clipboard-text="Take data from URL and put it here using Jquery" >
        <a href="#openModal" style="color: #fff;">Copy URL</a>
    </button>
</div>

And this is the popup box :-

<div id="popup1" class="overlay">
    <div class="popup">
        <span class="poptext">Copy URL to share the link</span>
        <a class="close" href="#">&times;</a>
        <div class="content">
            <input type="text" id="urlText" style="width:90%;">
        </div>
    </div>
</div>

This is the jquery i am using :-

$( "#obj" ).click(function() {
    $("#urltext").select();
});

I don't know where i am going wrong. Can anyone help me out in this?jquery

you changed id name in jquery. change urlText instead of urltext . It must be case-sensitive

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