What are some methods to manipulate the appearance of text with jquery?

I am having trouble with jQuery and it seems like it's not working properly. Can anyone help me locate the error? My aim is to create a "Read less" button that will show more content when clicked. However, when I click on "Read More", nothing happens. How can I resolve this issue?

$('.moreless-button').click(function() {
  $('.moretext').slideToggle();
  if ($('.moreless-button').text() == "Read more") {
    $(this).text("Read less")
  } else {
    $(this).text("Read more")
  }
});
.moretext {
  display: none;
}
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <!--Bootstrap-5-->
  <!-- Latest compiled and minified CSS -->
  <link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="294b46465d5a5d5b4859691c0718071b">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet" />


  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>GEM HODLERS CRYPTO NEWS</title>
</head>

<body>


  <!--Main-Content-->
  <div class="container col-lg-12 text-center Main-Content">
    <h1>#1 ON GOOGLE IN OUR CATEGORY</h1>
    <img src="https://gemhodlers.com/wp-content/uploads/dSection3.jpg" class="img-fluid" />
    <h2 class="imp-cap">
      In current growth models, we are forecasting 1 million visitors per month by EOY 2022.<br /> (Screenshot taken 30 October 2021.)
    </h2>
    <img src="https://gemhodlers.com/wp-content/uploads/dSection4.jpg" alt="logo-picture " class="img-fluid top-logo" />
    <h1>
      Quick question: Is your team looking for cost-effective advertising & marketing solutions from a reputable name in the crypto space, that guarantees maximum visibility and attention from willing investors, that will help your project grow and reach its
      maximum potential?
    </h1>
    <div class="moretext">
      <h1 class="collec-text">
        We are Gem Hodlers, a crypto-only news platform that gets heavy niche traffic from active and curious investors. We are also a full scale marketing agency. Through our platform, we offer different targeted marketing services, including various types of
        advertising, project review articles and summaries, press releases, email outreach, platform highlights, social media promotion, and more, all through our platform.
      </h1>
      <h1 class="collec-text">
        To summarize, we have our own crypto news platform that gets more than ¼ million visitors per month, that we currently offer various advertising and publications on, as well as other promotional material. We have ~6k email subscribers that we send weekly
        newsletters to that we feature our sponsored projects in. We also offer an add-on service to send a dedicated email to all our subs giving them your project info with instructions on how they can involved, amongst other services to help you connect
        with our highly niche audience.
      </h1>
      <h1>
        We are able to do this because we do not rely on anyone else’s platform.
      </h1>
      <h1>
        we connect you with those exact same investors that the websites above do, and stimulate the same growth, but for significantly less cost.
      </h1>
      <h1>
        and we've recently been getting a noticeably increasing amount of Polygon, Solana, Fantom, and Avalanche network traffic.
      </h1>
      <h1>
        If your team is paying for space on our platform, for any length of time, then it is fully yours, and all visitors will see it for the duration.
      </h1>
      <h1>
        We offer actual advertising and real-life marketing that leads to our client’s projects having higher valuations with more investors, and we offer our services to projects we have good reason to believe our audience would be interested in investing their
        hard-earned money into.
      </h1>
      <h1>
        Having all of that said… thank you for your time, and welcome to the World of Gem Hodlers!
      </h1>
    </div>
    <a class="moreless-button" href="#">Read more</a>
    <h2 class="bottom-text">The Gem Hodlers team</h2>



</body>

</html>

Answer №1

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <!--Bootstrap-5-->
    <!-- Latest compiled and minified CSS -->
    <link
      href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2e4c41415a5d5a5c4f5e6e1b001f001c">[email protected]</a>/dist/css/bootstrap.min.css"
      rel="stylesheet"
    />


    <!-- Latest compiled JavaScript -->
   <style>
      .moreinfo {
  display: none;
}
    </style>
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>GEM HODLERS CRYPTO NEWS</title>
  </head>
  <body>


    <!--Main Content-->
    <div class="container col-lg-12 text-center Main Content">
      <h1>#1 ON GOOGLE IN OUR CATEGORY</h1>
      <img
        src="https://gemhodlers.com/wp-content/uploads/dSection3.jpg"
        class="img-fluid"
      />
      <h2 class="important-caption">
        In current growth models, we are projecting 1 million visitors per month by EOY 2022.<br />
        (Screenshot taken on October 30, 2021.)
      </h2>
      <img
        src="https://gemhodlers.com/wp-content/uploads/dSection4.jpg"
        alt="logo-picture "
        class="img-fluid top-logo"
      />
      <h1 >
        Quick question: Is your team interested in cost-effective advertising &
        marketing solutions from a reputable name in the crypto space, guaranteeing maximum visibility and attention from willing investors to help your project grow and reach its potential?
      </h1>
      <div class="moreinfo">
        <h1 class="collective-text">
          We are Gem Hodlers, a crypto-only news platform attracting heavy niche traffic from active and curious investors. We also operate as a full-scale marketing agency. Through our platform, we provide various targeted marketing services, including different types of advertising, project review articles, press releases, email outreach, platform highlights, social media promotion, and more.
        </h1>
        <h1 class="collective-text">
          To sum up, we have our own crypto news platform with over a quarter-million monthly visitors where we currently offer various advertising options and publications, along with other promotional materials. We have approximately 6,000 email subscribers to whom we send weekly newsletters featuring sponsored projects. Additionally, we provide an add-on service to send a dedicated email to all our subscribers showcasing your project information along with instructions on how they can get involved, among other services aimed at connecting you with our highly specialized audience.
        </h1>
        <h1 >
           This is possible because we are not dependent on any external platforms.
        </h1>
        <h1 >
          We connect you with the same investors targeted by other websites, driving similar growth but at a significantly lower cost.
        </h1>
        <h1 >
          Recently, we have observed increasing traffic from Polygon, Solana, Fantom, and Avalanche networks.
        </h1>
        <h1 >
           If your team purchases ad space on our platform for any duration, it belongs exclusively to you, visible to all visitors throughout that time.
        </h1>
        <h1 >
          Our services encompass genuine advertising and practical marketing strategies that result in higher valuations for our clients' projects, attracting more investors. We extend these services to projects we believe would interest our audience in investing their funds.
        </h1>
        <h1 >
          With that being said, thank you for your time, and welcome to the World of Gem Hodlers!
        </h1>
      </div>
      <a class="view-more-button" href="#">Read more</a>
      <h2 class="footer-text">The Gem Hodlers Team</h2>
     
      <script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="cfa5bebaaabdb68ffce1f9e1ff">[email protected]</a>/dist/jquery.min.js"></script>
    <script>
      $('.view-more-button').click(function() {
  $('.moreinfo').slideToggle();
  if ($('.view-more-button').text() == "Read more") {
    $(this).text("Read less")
  } else {
    $(this).text("Read more")
  }
});
    </script>
  </body>
</html>

Answer №2

Ensure that you reference the jQuery files before utilizing them.

You can achieve this by either downloading the source files from this link and inserting

<script src="jquery-3.x.x.min.js"></script>

Alternatively, for a more convenient approach, you can simply utilize a CDN:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>

Answer №3

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <!--Bootstrap-5-->
    <!-- Latest compiled and minified CSS -->
    <link
      href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="56343939222522243726166378677864">[email protected]</a>/dist/css/bootstrap.min.css"
      rel="stylesheet"
    />
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

    <!-- Latest compiled JavaScript -->
    <style>
      .moretext {
        display: none;
      }
    </style>
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>GEM HODLERS CRYPTO NEWS</title>
  </head>
  <body>
   
   
    <!--Main-Content-->
    <div class="container col-lg-12 text-center Main-Content">
      <h1>#1 ON GOOGLE IN OUR CATEGORY</h1>
      <img
        src="https://gemhodlers.com/wp-content/uploads/dSection3.jpg"
        class="img-fluid"
      />
      <h2 class="imp-cap">
        In current growth models, we are projecting 1 million visitors per month by the end of 2022.<br />
        (Screenshot taken on October 30, 2021.)
      </h2>
      <img
        src="https://gemhodlers.com/wp-content/uploads/dSection4.jpg"
        alt="logo-picture "
        class="img-fluid top-logo"
      />
      <h1 >
        Here's a quick question: Is your team seeking cost-effective advertising &
        marketing solutions from a trusted name in the crypto industry to gain maximum visibility and attention from potential investors, helping your project grow to its full potential?
      </h1>
      <div class="moretext">
        <h1 class="collec-text">
          We are Gem Hodlers, a crypto-only news platform attracting a large audience of active and curious investors. Additionally, we operate as a full-fledged marketing agency. Our platform provides various targeted marketing services such as advertising options, project reviews, press releases, email outreach, social media promotion, and more.
        </h1>
        <h1 class="collec-text">
          In summary, our own crypto news platform receives over a quarter-million monthly visitors, where we offer different advertising opportunities and publish promotional material. We also have approximately 6k email subscribers who receive weekly newsletters featuring sponsored projects. As an add-on service, we send dedicated emails to all subscribers providing detailed information about projects they can be involved in, among other services tailored to connect with our niche audience.
        </h1>
        <h1 >
           This is made possible because we operate independently without relying on external platforms.
        </h1>
        <h1 >
          We connect you with the same investors as other websites do, fostering similar growth at a significantly lower cost.
        </h1>
        <h1 >
          Recently, we've noticed a significant increase in traffic from Polygon, Solana, Fantom, and Avalanche networks.
        </h1>
        <h1 >
           When your team invests in space on our platform for any duration, it becomes entirely yours, reaching all visitors during that time.
        </h1>
        <h1 >
          We deliver real advertising and effective marketing strategies that elevate our clients' projects, attracting more investors. Our services are offered to projects that align with our audience's interests and investment preferences.
        </h1>
        <h1 >
          With all that said, thank you for taking the time to explore the World of Gem Hodlers!
        </h1>
      </div>
      <a class="moreless-button" href="#">Read more</a>
      <h2 class="bottom-text">The Gem Hodlers Team</h2>
     
      
    <script>
      $('.moreless-button').click(function() {
        $('.moretext').slideToggle();
        if ($('.moreless-button').text() == "Read more") {
          $(this).text("Read less")
          document.querySelector('.moretext').style.display = 'block';
        } else {
          $(this).text("Read more")
          document.querySelector('.moretext').style.display = 'none';
        }
      });
    </script>
  </body>
</html>

Answer №4

Here is a helpful code snippet for you to use:

<!DOCTYPE html>
<html>
<head>
    <title>Page Title</title>
    <style>
        .reveal-open {
        overflow: auto;
        height: auto;
        }
        .reveal-closed {
        overflow: hidden;
        height: 100px;
        }
        .label-rml{
        border: 1px solid;
        padding: 2px;
        margin: 5px 5px;
        background: cornflowerblue;
        color: white;
        }
    </style>
</head>
<body>
    <div id="thediv" class="reveal-closed">
        Contrary to popular belief, Lorem Ipsum is not simply random text. 
        It has roots in a piece of classical Latin literature from 45 BC, 
        making it over 2000 years old. Richard McClintock, a Latin professor 
        at Hampden-Sydney College in Virginia, looked up one of the more obscure 
        Latin words, consectetur, from a Lorem Ipsum passage, and going through 
        the cites of the word in classical literature, discovered the undoubtable 
        source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus 
        Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 
        45 BC. This book is a treatise on the theory of ethics, very popular during 
        the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", 
        comes from a line in section 1.10.32.
    </div>
    <label class="label-rml" id="roadmap">Read More...</label>
    <script src="https://code.jquery.com/jquery-3.7.1.min.js" integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo=" crossorigin="anonymous"></script>
    <script>
        $("#roadmap").click(function() {
          $("#thediv").toggleClass("reveal-closed").toggleClass("reveal-open");
          if($(this).html()=='Read More...'){
            $(this).html('Read Less');
          }else{
            $(this).html('Read More...');
          }
        });
    </script>
</body>
</html>

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

allowing absolutely positioned region to expand

For further information, please visit this page: test page In the process of designing a website, I have implemented a sidebar featuring an accordion style vertical navigation bar. The sidebar is set to be absolutely positioned in relation to its containi ...

The if statement remains active without being disabled

Currently, I am working on coding a bot for my school that includes a feature allowing students to talk in a voice channel if they send a specific message and the teacher reacts with a specific emoji. Below is the code snippet: client.on('message&apos ...

What is the best way to position text next to an image?

My dilemma involves aligning images from left to right with text beside each image. Here is a snippet of the code I used: <div> <p style="float: left;"><img src="images/pic1.jpg" height="141px" width="212px" border="0px"></p> & ...

Filling a ButtonGroup in React with Buttons from an array

When trying to populate a ButtonGroup with Buttons using array.map(), I encounter an issue where the buttons do not appear. Interestingly, I used the same method successfully to populate a DropdownButton with MenuItems. Here is the functional DropdownButt ...

How can I retrieve data from a script tag in an ASP.NET MVC application?

I'm struggling to figure out how to properly access parameters in a jQuery call. Here is what I currently have: // Controller code public ActionResult Offer() { ... ViewData["max"] = max; ViewData["min"] = min; ... return View(paginatedOffers ...

How can HTML5 geolocation be utilized to provide real-time latitude and longitude coordinates for integration with the Google Maps API?

I am currently working on a project where I need to dynamically fetch longitude and latitude values from the browser geolocation and then include them in the options array for the Google Maps API. Here is the code snippet I am using: function initMap(){ ...

Steps to place a URL and Buttons over an existing header Image

1) I am working with a header JPEG image that is 996px wide and includes a square logo on the left side. My goal is to use only this square logo section and add an href tag so that when users hover over it, the cursor changes to a hand pointer and they are ...

Effortlessly implement CSS styling in a scoped shadow element with Vue3

I am facing an issue with applying styles to an anchor element in my code. Below is a snippet of the code: <template> <custom-button> #shadow-root (open) <a href="#"></a> <other-custom></other-c ...

Looking to align three divs side by side in the center

My goal is to have three buttons aligned side by side, but I want them center-aligned instead of floated to the left. I have already set the display to inline-block and vertical align to top. div.rotateBtn input { background-image: url(""); margin-l ...

Learn the effective way to customize the primary button text color in Bootstrap 4 using SCSS styling

Looking to customize the .btn-primary text color. I attempted to modify the background color in _variables.scss by adding the following line: $primary: #a1c1b6; However, I was unable to change the text color despite trying various options. // not working ...

Strategies for Emphasizing Individual Content Links on a Single-Page Website with Dynamic Content Replacements

My website consists of a single page with content that gets replaced using jQuery when the menu is clicked. Even though the links do not lead to different pages, just different divs, I want the menu to behave like a typical website menu with three states: ...

Fotorama Slider experiencing display issues upon first loading

Our website features the fotorama slider which can be viewed here: However, we are experiencing an issue where upon the initial page load, the slider appears in a small area in the top left corner of the container. It only displays correctly when the brow ...

Ways to extract particular items from a JSON array and store them in a JavaScript array

I am dealing with an external JSON-file structured as follows: { "type":"FeatureCollection", "totalFeatures":1, "features": [{ "type":"Feature", "id":"asdf", "geometry":null, "properties": { "PARAM1":"19 16 11", ...

Positioning CSS Div After Absolute Positioning Div

Can anyone provide guidance on how to smoothly continue the flow of a page using CSS? Let me explain my current dilemma: I have 3 divs - div 1 (parent), div 1 (child), and div 2 (normal). The parent div is absolute, the child is relative. Everything seem ...

AngularJS enables the creation of a checkbox that toggles the visibility of content

As I develop a form, selecting 'Next Section' will reveal a new group of input fields organized into 8 sub-forms. Through checkboxes, I aim to dynamically display the relevant sub-form based on user selections. For example, if there are 5 checkbo ...

Utilizing the jexcel plugin to seamlessly integrate arrays for a personalized subtitle editing experience

Could you please assist me in understanding how to utilize the jexcel plugin for pushing arrays? To achieve the push functionality, I would like it to behave similarly to arrays containing 6 different colors as outlined below: Subtitles = orange, Caption ...

What are some creative ways to provide video responses to a list of questions?

My task is to create a popup that includes questions and video responses. The challenging aspect for me is how to ensure each question displays a different video in the same location. Additionally, when the user first opens the popup, the initial question ...

What could be causing my bootstrap cards to have varying lengths?

I'm currently working on a project that requires me to apply a specific responsive design using HTML Bootstrap classes. I've managed to format it the way I want, but I'm puzzled as to why the width of my cards within rows is inconsistent in ...

What is preventing this from functioning in IE10 while it works fine in IE7?

I am currently facing an issue with a form that has been divided into three sections, each with a "next" and "back" button to navigate through the sections. The functionality works perfectly in Firefox, Chrome, and IE7, but not in IE10+. Specifically, the ...

Using JQuery to rebind() after resetting the count

In my game, I have implemented a feature to ensure that the start button can only be clicked once each time it appears in order to prevent the function from loading multiple times. I wrote some code that tracks the number of clicks and unbinds the click e ...