Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8735995
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:12:07+00:00 2026-06-13T10:12:07+00:00

I am trying to write a basic blogging platform, and I want to offer

  • 0

I am trying to write a basic blogging platform, and I want to offer users the ability to copy code within a pre block to their clipboard.

I am using ZeroClipboard to achieve this. Once the document is ready, I loop through each pre on the page, adding a clipboard item to it as follows:

    $(document).ready(function() {

        ZeroClipboard.setMoviePath( 'ZeroClipboard/ZeroClipboard.swf' );
        var preNum = 1

        $('pre').each(function() {
            // Get a unique id for the element I will be inserting
            var id = 'copy-btn-' + preNum++
            // Capture the text to be copied to the clipboard
            var text = $(this).text()
            // Insert the element, just before this
            $('<div class="copy-btn" id="' + id + '-cont"><i class="icon-file icon-white" id="' + id + '"></i></div>').insertBefore(this)
            // Capture the newly inserted element
            var elem = $(this).prev()

            // Create the clip, and glue it to the element
            var clip = new ZeroClipboard.Client();
            clip.setText(text)
            clip.glue(elem)
       })
   });

When I try to do this, the javascript console reports: Uncaught TypeError: Cannot read property 'zIndex' of undefined

My current understanding of the problem is that the inserted element is not yet available in the dom when I try to glue the clip to it, which is why no gluing is occurring.

Anybody know how I might be able to accomplish this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T10:12:08+00:00Added an answer on June 13, 2026 at 10:12 am

    From the Gluing instructions:

    You can pass in a DOM element ID (as shown above), or a reference to
    the actual DOM element object itself.

    Your code doesn’t work because you’re passing a jQuery object to it.

    You can pass the ID:

    clip.glue(id + '-cont')
    

    Or an actual DOM element reference:

    clip.glue(elem[0])
    

    The above example uses the shorthand for the .get() jQuery object method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a basic synchronisation program to copy files between two directories.
Hiya im trying to write a code for basic 1D Monte-Carlo integration. To do
I'm trying to write some simple socket code that has the following basic form
I am trying to write some basic Outlook code that should support Outlook 2003,
I'm trying to write the most basic application for windows phone 7 and want
I'm trying to write a basic dialog box. I want to be able to
I'm trying to write basic assert test: def assert_session_has ( sessionvar ) return assert_not_nil
I'm trying to write a basic script which creates a UI. I have reduced
I'm trying to write a basic client/server echo program, to test the usage of
I'm trying to write a basic DST converter. I have a segmented control with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.