Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-07-2012, 08:35 AM   PM User | #1
Subyne Simean
New Coder

 
Join Date: Nov 2006
Posts: 21
Thanks: 3
Thanked 1 Time in 1 Post
Subyne Simean is an unknown quantity at this point
jQuery 'hiding' content on search output page

Hello I was wondering if you may be able to help with this problem.

I have a PHP search results output page. In the search results I want to have a copy button next to some of the results so users can easily copy them to their clipboard.

The jQuery I'm using only works when I output the following script along with the results (i.e. it won't work if I just have it on the page statically).

Code:
$('.copy').click(function() {
    
    var row = $(this).closest('td');

    
    var txt = row.find('span:first');

    
    window.clipboardData.setData('Text', txt.text());

    
    var range = document.body.createTextRange();
    range.moveToElementText(txt[0]);
    range.select();
});

the HTML...

<td><span>Name from DB here</span> <button class="copy">COPY</button></td>

<td><span>Phonefrom DB here</span> <button class="copy">COPY</button></td>

<td><span>Email from DB here</span> <button class="copy">COPY</button></td>
So yes it works if I do it that way, but everything above the script gets hidden (behaves like the elements have display: none set). I have a form above the script that needs to be on the page.

Please help!!!
Subyne Simean is offline   Reply With Quote
Old 12-07-2012, 11:00 AM   PM User | #2
VIPStephan
The fat guy next door


 
VIPStephan's Avatar
 
Join Date: Jan 2006
Location: Halle (Saale), Germany
Posts: 7,600
Thanks: 5
Thanked 865 Times in 842 Posts
VIPStephan is a jewel in the roughVIPStephan is a jewel in the roughVIPStephan is a jewel in the rough
I don’t see anything that would hide the content. Use a debugging tool (usually built into the browser already) and see what really happens. Also, you are adding a “DOM ready” function to your script or loading it at the end of the document, aren’t you?
__________________
Don’t click this link!
VIPStephan is online now   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:28 PM.


Advertisement
Log in to turn off these ads.