Display and conceal information upon tweeting

Can anyone help me troubleshoot an issue with hiding the Twitter button after displaying new content? I tried adding a script to make it work, but it's still not functioning properly. Any insights on what I might be doing wrong would be greatly appreciated. Thanks.

----UPDATE----

Adding this script seems to be causing the problem:

<script type="text/javascript" src="//platform.twitter.com/widgets.js"></script>

and

   <script src="https://code.jquery.com/jquery-1.12.4.js"></script>

----UPDATE END----

Below is the code snippet:

(function($) {

  var win = null;

  $.fn.tweetAction = function(options, callback) {

    // Default parameters of the tweet popup:

    options = $.extend({
      url: window.location.href
    }, options);

    return this.click(function(e) {

      if (win) {
        e.preventDefault();
        return;
      }

      var width = 550,
        height = 350,
        top = (window.screen.height - height) / 2,
        left = (window.screen.width - width) / 2;

      var config = [
        'scrollbars=yes', 'resizable=yes', 'toolbar=no', 'location=yes',
        'width=' + width, 'height=' + height, 'left=' + left, 'top=' + top
      ].join(',');

      win = window.open('http://twitter.com/intent/tweet?' + $.param(options),
        'TweetWindow', config);

      (function checkWindow() {

        try {
          if (!win || win.closed) {
            throw "Closed!";
          } else {
            setTimeout(checkWindow, 100);
          }
        } catch (e) {

          win = null;
          callback();
        }

      })();

      e.preventDefault();
    });
  };

})(jQuery);

$(document).ready(function() {

  $('#tweetLink').tweetAction({
    text: 'First tweet',
    url: '#',
    via: 'website'
  }, function() {


    $('hidden-text')
      .show();

    $(".hidden-text").removeClass("hidden-text");


  });

});

$(document).ready(function() {
  $("p").click(function() {
    $(this).hide("slow");
  });
});
.hidden-text {
  display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p>Tweet to show content.
  <a href="https://twitter.com/intent/tweet?screen_name=your_twitter" class="twitter-mention-button" id="tweetLink" data-show-count="false">Tweet to @your_twitter</a>
            </p>
            <p class="hidden-text">thank you for tweeting !</p>

UPDATE Optimized some javascript

$(document).ready(function () {

$('#tweetLink').tweetAction({
    text: 'First tweet',
    url: '#',
    via: 'website'
}, function () {

    $('hidden-text')
        .show("slow");

    $(".hidden-text").removeClass("hidden-text");
    $("#hide-me").hide("slow");
});

});

UPDATE 3

After checking the console, I noticed an error message:

Uncaught TypeError: $(...).tweetAction is not a function

Also, I updated the JQuery CDN, but now when clicking on "Tweet to @your_twitter," it changes the URL in the same window instead of opening a new one. Any suggestions on how to fix this?

Solved

I had to remove some CDNs

 <link href="https://get.gridsetapp.com/35679/" rel="stylesheet"/>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.0/themes/base/jquery-ui.css">
<!--<script src="https://code.jquery.com/jquery-1.12.4.js"></script>    -->
<!--<script   src="https://code.jquery.com/ui/1.12.0/jquery-ui.min.js"></script>-->
<!--<script src="https://code.jquery.com/ui/1.12.0/jquery-ui.js"></script>-->


<script src="https://code.jquery.com/ui/1.12.0/jquery-ui.js"></script>
<!--<script   src="https://code.jquery.com/jquery-3.1.0.min.js" ></script>-->

Answer №1

If the functionality ceases to work after implementing these scripts, try adding the scripts one at a time and monitor your JavaScript console for any errors. This process should help pinpoint the source of the issue.

Additionally, verify that the libraries are not being loaded multiple times. If another jQuery library has already been loaded, it may cause conflicts and prevent the scripts from functioning properly.

Answer №2

There are two syntaxes mentioned here, but they are not relevant to the issue at hand.

<a href="https://twitter.com/intent/tweet?screen_name=your_twitter" class="twitter-mention-button"
               id="tweetLink" data-show-count="false">Tweet to @your_twitter/a><a href="https://twitter.com/intent/tweet?screen_name=your_twitter" class="twitter-mention-button"
               id="tweetLink" data-show-count="false">Tweet to @your_twitter </a> <!--Closing the tag-->

$('.hidden-text').show(); //class picker

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Having trouble with adding the copy to clipboard feature

I'm having trouble implementing a copy to clipboard option on my color selector. The goal is to display the selected color on an h3 tag and create a background color generator. Each time a color is chosen, it should appear on screen for us to easily c ...

Handling session expiration in ASP.NET MVC when making an AJAX call by redirecting to the login page

I'm currently learning ASP.NET MVC and I'm a newbie in it, so I'm struggling to find a solution for a specific problem. If anyone has encountered this issue before, I would appreciate any advice. Thank you! In my project, I am using ASP.NET ...

Search for and swap HTML text. Exclude any web links

After developing a simple script to search and replace strings within the DOM, I encountered an issue where URLs of links were being affected as well. For instance, replacing "example" with "my example" resulted in breaking the following link; <a href ...

What is the best way to showcase a single item from an array in Vue.JS?

Suppose I have a list of items in Vue.JS data () { return{ items: [ { itemID: 5, itemText: 'foo' }, { itemID: 3, itemText: 'bar' } ] } } Now, if I want to show the item with the itemID of 3 i ...

Error: The variable 'xxxxxx' is not recognized

Encountering an issue while trying to pass data via an onclick event and receiving the error message "Uncaught ReferenceError: 'xxxxxx' is not defined" var ShowDetails = function (insuredID) { $.ajax({ type: "GET", ...

Issue with specific route causing server to throw 500 error

Recently, I have been working on a small school project that involves creating our own API and connecting it to an Angular front end. While following some tutorials, I encountered an issue where my application started throwing internal server error 500 af ...

Display a specific section depending on the user's input by utilizing either ng-if or ng-show

I have a scenario where I need to display one of two sections based on user input. If the user selects 'Daily' in the first 'type' input, I want section 1 to appear (Enter start date and hour). For any other type selection, I want secti ...

Creating components through the command line while managing multiple projects using Angular CLI 6

Currently, I am utilizing the most recent Angular CLI version (v6). Within my codebase resides a collection of applications housed within the projects directory. My objective is to create and organize various modules and components within these projects v ...

What is the reason for the ID "home-ad" not functioning properly in Firefox?

While working on some CSS styling, I encountered an issue with the ID "home-ad" not displaying properly in Firefox. The box model was showing a content size of 0x-40 (with 40 being the padding value). Interestingly, when I changed the ID name, the code wor ...

Display an image from a Google image search when hovering over a specified data attribute

My goal is to add a code snippet that will assign a class of "hoverme" to a table cell. When a user hovers over that cell, an ajax query will be triggered using the data attribute containing information stored there to perform a Google search. Below is a ...

Placing HTML text on top of a three.js renderer

I have been attempting to overlay HTML text onto my three.js sketch, but adjusting the z-index does not seem to be working. While I know that I could utilize innerHTML, the issue arises when I need to also use the onclick attribute, which is not the main f ...

What is preventing me from setting a background image in Angular 13?

Trying a different approach based on advice from Stack Overflow, I attempted the following: <div [style.background-image]="'url(https://picsum.photos/200)'"></div> Unfortunately, this resulted in no effect and the image was ...

Gathering information from various web pages simultaneously without the need to manually navigate through each page using a webdriver

I'm new to the world of web scraping and I've successfully developed a program that allows me to extract specific, dynamic data by utilizing the selenium web driver. My current project involves scraping data from a FAQ page in order to gather in ...

Utilizing group by date feature in Angular ag-Grid

I'm working on setting up an ag-grid with columns for date, time, and location. Below is the code snippet: list.component.ts columnDefs: any = [{ headerName: 'Date', field: 'date', valueFormatter: (data: any) => { ...

Looking to Share Your Words on Tumblr?

When it comes to interacting with Tumblr, I have no issues using the GET method. However, as soon as I attempt to use the POST method for my Tumblr blog, an error is thrown: ({"meta":{"status":401,"msg":"Not Authorized"},"response":[]}); Below is the cod ...

Dividing a sentence by spaces to isolate individual words

Recently, I encountered a challenging question that has me stuck. I am working on creating an HTML text box where the submitted text is processed by a function to check for any links. If a link is detected, it should be wrapped in anchor tags to make it cl ...

Placing an image on the chosen option of a <mat-select> using Angular Material

I have incorporated Angular Material into my Angular 2 project, and I am trying to insert a static image (HTML element) in the selected value of mat-select. Unfortunately, I have been unable to find a solution for this issue. Is there anyone who can ...

axio. to retrieve the information stored in an alternate document

Seeking assistance in utilizing API data in a separate file. I have three files: api.jsx import axios from 'axios'; export const api = (url, data) => { const { path, method } = url; let result ={}; axios({ method: ...

Change the div attribute when clicking on a corresponding link

For the full code, please visit: https://plnkr.co/edit/6TTLVcsXLV7C1qXSMQV0?p=preview Here is an angular ui bootstrap accordion with nested panels: <uib-accordion close-others="oneAtATime"> <div ng-repeat="sub in subdivisions"> < ...

Issues with passing Angular directive attributes to the scope were encountered

I am having an issue with my angular directives where the arguments are not being passed into the scope: app.directive('sectionLeft', function() { return { restrict:'E', scope: { sectionContent: '=', s ...