Unable to trigger .click event in Jquery after modifying CSS attributes

Looking for a solution with my HTML code snippet:

<h2 class="more-button">Read More</h2>

I want to change the position of another div when this button is clicked. I am trying to achieve this using:

$(".more-button").click(function(){
    $(".hidden-block").css("right", "110%");
});

FIDDLE : https://jsfiddle.net/wfxxkk3x/

Unfortunately, the code has no effect at all. I have attempted various solutions without success. Any assistance would be greatly appreciated.

Answer №1

Everything looks good in your code. I noticed in your js fiddle here that you are using "hidden-block" as an ID instead of a Class.

Just update your jquery selector to use "#" for IDs.

For example:

$(".more-button").click(function(){

    // hidden-block is an id
    $("#hidden-block").css("right", "110%");

}); 

I hope this information helps!

Answer №3

Have you applied any CSS to your

<div class="hidden-block"></div>
? If not, the values "right", "110%" will have no effect.

Try adding either position: absolute; or position: relative; to your .hidden-block which should allow you to make adjustments to its placement.

If using jQuery without a stylesheet, you can achieve similar results like this:

$(".more-button").click(function(){
  $(".hidden-block").css({"position":"relative", "right":"110%"});
});

Answer №4

It is essential to specify the position of the div for it to respond to the right property.

position: relative;

or

position: absolute;

Answer №5

I observed in your code snippet that "hidden-block" is being referenced as an ID rather than a CSS class. Therefore, your JavaScript should be:

$("#hidden-block").css("right", "110%");

Have you imported the jQuery library? I couldn't locate it in the External Resources of your fiddle.

Once you modify the selector from . to # and include the jQuery library, your code will function correctly. Experiment with changing the value from 110% to another one to see the outcome.

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

JQuery is throwing an unhandled reference error

I'm currently working on a jQuery script that looks like this: <script type="text/javascript"> $(document).ready(function () { var $containerHeight = $('.container').height(); if ($containerHeight < 760) { ...

Troubleshooting problem with custom Angular directive integrating KineticJS

Hey there, I'm currently working on putting together a KineticJS application in Angular and need to resolve a minor issue. While following an example for setting up a draggable shape in AngularJS using KineticJS from this link: , I encountered this er ...

What is the best way to eliminate the external pause button?

My website contains the following HTML snippet: <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="a ...

Attempting to insert form information into a database by making an Ajax call with PHP

I am facing issues with adding data to a local database using my form. Here is my addproducts.php page: <?php $title = "Products"; include("Header.php"); include("PHPvalidate.php"); ?> <script src="AjaxProduct.js"></script> <art ...

I am getting an undefined response when attempting to retrieve documents from a database using Mongoose

My goal is to develop a function that takes two arguments, username and email. If either of them is already in the database, the user should not be able to register. function checkAll(username, email) { let num = 0; User.find({}, (err, result) => { ...

Access and retrieve real-time JavaScript variables directly from a website

Question: I am curious about the possibility of accessing JavaScript variables on a website from C#. Since the scripts are on the client side, is it possible to read their values live through C#? Any assistance or guidance on this matter would be greatly ...

Retrieve the title of the page that triggers the loading of another page through JQuery

My ASP.NET/C# page utilizes jQuery to load a Navigation.aspx page which includes my header and navigation buttons: <script> $(function(){ $("#nav-placeholder").load("Navigation.aspx"); }); </script> Within t ...

Hide a popup once a POST request is sent

My website features a login modal that appears when the user clicks on the login button. However, I encountered an issue where the modal remains open even after entering valid credentials and redirecting to another page. This problem persists regardless of ...

Incorporating a javascript library or plugin into Vue.js code

Hey there, I recently came across the really cool component called vue-social-sharing. It's my first time using a library like this and I'm a bit confused on how to set it up properly. I've installed it through NPM, but when it comes to the ...

Is there a way I can retrieve the appended link text upon clicking?

Hello everyone! I have successfully created my own jQuery/JavaScript auto complete search suggestions div. I have implemented a feature where it pulls in an XML dictionary full of words and uses regular expressions to suggest matches based on user input. H ...

Sending a jQuery variable to an external PHP script

Utilizing the HTML5 Geolocation API, I am able to retrieve latitude and longitude coordinates which I then need to pass to an external PHP file. This PHP file (getPosition.php) retrieves JSON variables from my database, allowing me to utilize them in geo.j ...

The usage of Arrow Functions within Object Literal Syntax

I can't seem to understand why an arrow function within an object literal is invoked with window as the context for this. Any insights on this would be greatly appreciated. var arrowObject = { name: 'arrowObject', printName: () => { ...

Stop Bootstrap Modal from displaying with the help of an ajax error

Is there a way to prevent the Modal from appearing when an ajax call returns an error? I've tried using the code snippet below, but it didn't work for me. Here's how my ajax call is set up: $.ajax({ url: url, data: data, dataTyp ...

Bootstrap's hidden navigation bar feature

I noticed that my navbar changes from transparent to opaque when scrolling. I am trying to achieve a similar effect like the one in this example: https://i.sstatic.net/00uPM.png Initially, my navbar looks like this: https://i.sstatic.net/iMyYL.png As y ...

Div remains fixed while scrolling until the footer is reached

Hi there, I could really use some assistance with a jQuery issue I'm facing. I've been watching tutorials in an attempt to find a solution, but being new to jQuery, I'm struggling. My goal is to scroll a fixed div down the page, however when ...

exchanging the positions of two animated flipdivs

Hey there! I'm facing a little challenge with my two divs (let's call them div1 and div2). One of them has a flip animation on hover, while the other flips on toggle click. My goal is to swap these two divs by dragging and dropping them. I' ...

Positioning the footer to sit at the bottom of my webpage, leaving a pleasing margin at the top

One technique I frequently use to ensure my footer stays at the bottom of my page is by utilizing an empty div. Here's how the code looks: <body> <div id="canevas"> <article>My website's content</article> ...

Executing multiple Ajax requests on CodeIgniter 3 from two separate pages

I am facing a critical need for a code review and unfortunately, I am unsure of where else to seek assistance besides here. Let me outline my current task: I am working on a user profile page that is designed to showcase users' comments. Users have t ...

Node.js Express post query failing to set content type

I have a POST request implemented with the express framework to submit a query to a rest api. Here is the relevant code snippet: var request = require('request'); app.post('/compute', function(req, postResponse) { var queryJSON = re ...

It seems that the Bootstrap 4 Modal Pop up window is having difficulty closing

I recently completed a project on creating a matching game. After all the cards are successfully matched and the game finishes, a congratulatory modal pops up. However, I encountered an issue where the modal would not close after clicking the "Play Again" ...