0

I have a server query, that queries a minecraft server and displays its status.It stores the ip and the server name in a variable and displays it with jquery in a single loop.

I want the dispalyed server name to be selectable onclick, but whatever i try it doesnt work

the code

$('.servercontainer .serverdata span[rel=\"'+serverarray[i]+'\"]').html(servername[i]);

here servername is the variable which contains the servername, server ip contains the ip and servercontainer is the class of the div that displays all the data.

I want to be able to select the server name when clicked on.

Thanks for reading this
edit: the servername is what i want selected. When a person clicks on the text, the whole text has to be highlighted so that all he has to do is ctrl+c to copy it.

Sorry for the confusion

1
  • 1
    What do you mean by "select"? Highlight? Link to? can you share what you have tried? Commented May 15, 2014 at 14:25

3 Answers 3

1

Not sure to understand.. If you mean that u want the servername to be clickable and linking to the server IP, you can do:

$('.servercontainer .serverdata span[rel=\"'+serverarray[i]+'\"]').html("<a href='"+serverip[i]+"'>"+servername[i]+"</a>");
Sign up to request clarification or add additional context in comments.

Comments

0

Do you mean this:

<SCRIPT>$(document).ready(
    function() {
        $('.copyText').click(
            function() {
                if ($('#tmp').length) {
                    $('#tmp').remove();
                }
                var clickText = $(this).text();
                $('<textarea id="tmp" />')
                    .appendTo($(this))
                    .val(clickText)
                    .focus()
                    .select();
        return false;
    });
$(':not(.copyText)').click(
    function(){
        $('#tmp').remove();
    });

});
</SCRIPT>
<SPAN CLASS="copyText">Click Me!</SPAN>
<SPAN>Not Me!</SPAN>

Live Demo at http://jsfiddle.net/Wx4YN/1/

If yes, don't forget that this need jQuery

Have some little bugs when you use div or p.

2 Comments

this exactly what i want. just how do i do it.
You must add the copyText class to your text container.
0

Hard to answer without more context, but assuming you're just trying to grab the text value of the clicked item, try using the .text() method...

example:

$('.servercontainer .serverdata span[rel=\"'+serverarray[i]+'\"]').click( function () {
  var capturedText = $(this).text();
  // do something with the captured text...
});

... instead of .html() if you just want the text.

Comments

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.