Current status of the Ning Platform is always available on the Ning Status Blog.

Forum

I am trying to add this custom javascript and css code in a page

<script src="http://code.jquery.com/jquery-1.11.0.min.js" type="text/javascript" charset="utf-8"></script>
    <script type="text/javascript" charset="utf-8">
    $('.subject').append('<button class="download" style="float: right;">DOWNLOAD</button>');

 $('.download').click(function() {
     $(this).parent().next('table').slideToggle('fast').css('display', 'block');
    });
  </script>

<style>
    .subject {
      color: #009fdb;
      display: block;
      font-size: 20px;
      margin: -5px 0px 5px;
      width: 100%;
    }
    .files {
      display: none;
    }
  </style>

Every time i got this error

<section class="handouts">

        <h1>Frequently asked subjects</h1>
        <p class="subject">ACC311 - Fundamentals of Auditing </p>
        <table class="files" align="right">
          <tr>
            <td>PDF</td>
            <td>PPT</td>
          </tr>
        </table>
        
</section>

You need to be a member of Ning Creators Social Network to add comments!

Join Ning Creators Social Network

Email me when people reply –

Replies

  • Hello,

    I got it to work on my Ning 2 site by adding the code to the Custom Code box, rather than the Head box on the custom page.

    Also you don't need to load the jQuery library because Ning does that for us already.  Ning's version of jQuery uses x$ rather than just $ so making that change made the download button appear for me.

    I used this code in the Custom Code box:

    <script type="text/javascript" charset="utf-8">
        x$('.subject').append('<button class="download" style="float: right;">DOWNLOAD</button>');

     x$('.download').click(function() {
         x$(this).parent().next('table').slideToggle('fast').css('display', 'block');
        });
      </script>

    <style>
        .subject {
          color: #009fdb;
          display: block;
          font-size: 20px;
          margin: -5px 0px 5px;
          width: 100%;
        }
        .files {
          display: none;
        }
      </style>

    Try it out here: http://jqueryhelp.ning.com/page/test-download-button

    Best wishes!

    TJ

    • Hi TJ!

      I checked your page and the code is working like a charm. I use the same code on my page but i got the same error i mentioned above. I don't know why i am getting this error. But i figured out something that, when i try to put HTML tags in javascript code, the custom box gives error. When i put the button tag in javascript code like this button> instead of this <button> the custom box accept the code. But the download button does not appear sometime. I am sure you will resolve my problem.

      Regards

      • Hello Innocent, try it like this..  It sounds like you have something in the head with the class or id the same as what you have in your script..  ".subject"  So we will add user generated to your code. Hopefully this helps.  You have a great day.

        <script type="text/javascript" charset="utf-8">
            x$('DIV.xg_user_generated .subject').append('<button class="download" style="float: right;">DOWNLOAD</button>');

         x$('DIV.xg_user_generated .download').click(function() {
             x$(this).parent().next('table').slideToggle('fast').css('display', 'block');
            });
          </script>

        <style>
           DIV.xg_user_generated .subject {
              color: #009fdb;
              display: block;
              font-size: 20px;
              margin: -5px 0px 5px;
              width: 100%;
            }
           DIV.xg_user_generated .files {
              display: none;
            }
          </style>

        • Hi George!

          Thanks for your great help. I have tried your modified javascript, but unfortunately it's still not working. I tried many things but the only working thing is that I need to break the starting tag of the button (<button>)to(button>), otherwise the code does not accept by the custom box. But the broken tag create problems and does not work every time. I think the javascript is not accepted if it got any html tag. I also try to put <input type="button"> instead of <button> but i got the same error. :(

          • I'm sorry it didn't work. :-(

            If you can send me a link to the page your adding this code to and I'll see if I can figure out the problem, like TJ said it should be working. We should be able to just target the individual page you are working on and add the code to your NC custom code box..

  • Okay, this should do the trick. The code goes in your NC custom code box. All the JavaScript and CSS have been compiled into one JavaScript code.

    If you change THE PAGE to a different page just change the page name in the first line of the code. What's in there right now is     "test-download-button"

    <script type="text/javascript" charset="utf-8">
    x$(document).ready(function(){0<=document.URL.indexOf("test-download-button")&&(x$(".subject").append('<button class="download" style="float: right;">DOWNLOAD</button>'),
    x$(".subject").css({color:"#009fdb",display:"block","font-size":"20px",margin:"-5px 0px 5px",width:"100%"}),
    x$(".files").css({display:"none"}),
    x$(".download").click(function(){x$(this).parent().next("table").slideToggle("fast").css("display","block")}))});
    </script>

  • It might be better doing it this way. Just add this code where you added it originally for each individual page.

    <script src="http://bit.ly/2dnMxi8" type="text/javascript" charset="utf-8"></script>
    <style>
        .subject {
          color: #009fdb;
          display: block;
          font-size: 20px;
          margin: -5px 0px 5px;
          width: 100%;
        }
        .files {
          display: none;
        }
      </style>

    • Hi George!

      Thanks for putting your head in it. I tried your new script, but unfortunately I got the same error. Then I use the external file you mentioned above the script is loaded, but I think its not working can you please take a look at it.

      http://vuhelp.pk/page/test-download-button

      Thanks again. :)

      • I've noticed the HTML portion of your code is in the head of the network it should not be there. See image below.



        And in your custom code box you have a misplaced ending script tag, which can cause errors. I don't see any of the codes in this discussion including mine installed on your network, except the HTML that is in the HEAD of your network.

        Here's what it looks like now in your custom code box
        <!--
        <script type="text/javascript" src="//s.skimresources.com/js/39610X1024039X3634.adunit.js">
        -->
        </script>

        Move the ending script tag so it looks like this

        <!--
        <script type="text/javascript" src="//s.skimresources.com/js/39610X1024039X3634.adunit.js"></script>
        -->

        When you fix those two errors try the codes again and if it doesn't work let me know and I'll have another look.

This reply was deleted.

Latest Activity

Aubrey Williams replied to Aubrey Williams's discussion
SSL Solution
"I was told in support chat that someone would contact me about this on Monday September 18th. Of co…"
5 minutes ago
Croatia replied to Kyryl_Ning_Support's discussion
Servers maintenance
"Hi creators, what's going on here? is there any news or activity? it looks like everyone is sleepin…"
yesterday
Kyryl_Ning_Support replied to Kyryl_Ning_Support's discussion
Servers maintenance
"Hello, Trish!
Could you please specify what kind of issue you are experiencing at the moment so we…"
yesterday
Trish Urquhart replied to Kyryl_Ning_Support's discussion
Servers maintenance
"Thanks, we are still having the problem. How long until it's fixed?
Thanks
Trish"
yesterday
Kyryl_Ning_Support replied to Kyryl_Ning_Support's discussion
Servers maintenance
"Hello, Anam!
So far we have resolved all the major issues related to server maintenance.
If you sti…"
yesterday
Kyryl_Ning_Support commented on Gerard Nealy's blog post SSL Certification
"Hello, Gerard!

Our developers are currently working on the SSL certificate for 3.0 networks, so I…"
Friday
Ning via Facebook

Choose the best plan for an amazing Friday :) Prepare for a cool weekend with…

Anam replied to Kyryl_Ning_Support's discussion
Servers maintenance
"I have posted this as a support ticket and been told that they recognise it as a bug, and it would…"
Friday
More…

Meanwhile, you can check our social media channels