Enhance your Bootstrap Progress Bar by incorporating the width value within the CSS using CoffeeScript or jQuery

I'm attempting to create a function where every time the button is clicked, the progress bar increases by an extra 12.5% out of the total 100%. (Therefore, eight clicks will complete the progress bar to 100%)

Currently, it updates the text content but doesn't visibly move the progress bar.

Here's the code snippet I've written so far:

CoffeeScript

$(".mybtn").on 'click', (e) ->
    valuer = $("#progBarMsg").parent().attr('value')
    newVal = valuer + 12.5
    e.preventDefault()
    window.scrollTo(0, 0)
    $("#progBarMsg").parent().css("width", newVal+'%').attr('aria-valuenow', newVal)
    $("#progBarMsg").text("This is just a test")

Below is the view partial which displays the progress bar and button:

Rails Partial

<div class="progress">
  <div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="12.5" aria-valuemin="0" aria-valuemax="100" style="width: 12.5%;">
    <span id="progBarMsg">Step 1 of 8</span>
  </div>
</div>

<nav>
    <ul class="pager">
        <li class="mybtn"><a href="">Click to Update Progress Bar</a></li>
    </ul>
</nav>

Answer №1

Success at last:

Rails partial

<div class="progress-bar">
  <div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="25.0" aria-valuemin="0" aria-valuemax="100" style="width: 25.0%;">
    <span id="progressMessage">Step 2 of 10</span>
  </div>
</div>


<nav>
    <ul class="pager">
        <li class="buttonClick"><a href="">Click here to advance Progress</a></li>
    </ul>
</nav>

Coffeescript

$(".buttonClick").on 'click', (e) ->
    value = $("#progressMessage").parent().attr('aria-valuenow')
    newValue = Number(value) + 25.0
    e.preventDefault()
    window.scrollTo(0, 0)
    $("#progressMessage").parent().css("width", newValue+'%').attr('aria-valuenow', newValue)
    $("#progressMessage").text("Testing in progress")

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

Tips for keeping my wordpress menu at the forefront

This piece of code is responsible for controlling the main menu on my website. Currently, it's set up so that when I scroll down, the menu disappears, and when scrolling up, it reappears. However, I would like the menu to always remain displayed at t ...

Does this extensive combination of pseudo classes hold true?

Here's the code snippet I am working with: .fontmenu .fontlist{ position: absolute; bottom:30px; display:none; } .fontbutton button:hover .fontmenu .fontlist{ display:block; } <div class="fontmenu"> ...

Jquery adds a fun, wobbly effect to animations

I'm experiencing an issue with the animation I've implemented causing some slight shaking and wobbling of the text and certain elements which is affecting the overall look. You can view a live example of this behavior here: This problem specific ...

When making an ajax request in Codeigniter, the form validation may return false

Greetings, I am in the process of creating a website using CI on Backend and I'm facing an issue with implementing a registration system without refreshing the page. When I use a post form submit, everything works fine with no errors. However, when at ...

Checkbox failing to trigger

Check out my code snippet here: http://jsfiddle.net/raficsaza/mgukxouj/ I'm facing an issue with the checkbox in this code. It seems to be stuck at a false value and I can't get it to change. Is there a way to work with the "input" tag instead o ...

What is the best way to incorporate a jQuery script to make an engaging slideshow on my website?

I've been trying to develop a slideshow similar to the one showcased on this website. First of all: I am using Kompozer. My website is not yet live as I am still in the process of putting it together on my computer. To give you an idea, here is the d ...

Best practice in AngularJS: Conceal/unveil fresh DOM elements or compile

Just starting out with AngularJS and looking to adjust button behavior on the fly. Coming from a JQuery background, I'm used to using element.attr('ng-click', 'controller.function()'). However, it seems that AngularJS requires co ...

Place the first paragraph within a div above another paragraph in the same div

Presently, I have this item: https://i.stack.imgur.com/0dBd9.png however, my objective is to achieve this look: https://i.stack.imgur.com/NEBZf.png The code snippet in question is as follows: .bonus-div { width: 290px; height: 29px; ma ...

Tips for updating the background color of a specific row

I have a piece of code that I am trying to modify with a specific condition. If {row.BB} is less than or equal to 100, I want to change the background color of the row with this value to red. Can someone help me achieve this? The code is linked to a data ...

How to style a webpage to be printed in CSS with A4 dimensions

Whenever I try to print my webpage, I encounter an issue where everything changes on the printout. I would like to be able to print a webpage that looks exactly like what is displayed on the screen. Here is an example of what I am looking for: enter imag ...

Having trouble with either posting a JSON using $.ajax() or reading it using PHP?

I'm struggling to identify the issue at hand. Here's my JavaScript function for sending JSON data: function send(var1, var2) { var result; att = window.location; $.ajax({ 'crossDomain': true, 'type&apos ...

Determine the dynamic height of content in a TypeScript file

Could you please provide guidance on obtaining the height of the content within this particular div element? For example, I need to calculate the dynamic height of the content. https://i.sstatic.net/2kNk3.png code .html <div class="margin-top-4 ...

``Inconvenience of Extensive URLs Being Displayed in Tables

I've been struggling to find a solution for the problem I'm facing with Chrome when it comes to wrapping long URLs in a table cell. Despite trying various solutions found online, including using the CSS code word-wrap: break-word;, I have not bee ...

Getting data from a wordpress database using javascript

After setting up a table named inspirationWall in my database with id and Visit_Count as INT, I inserted a row with id=1 and Visit_Count = 2. Now, attempting to fetch the Visit_Count value in WordPress and show it in an alert for testing purposes. I have ...

Having issues with the right margin in HTML5 canvas and struggling to remove the scroll bar

I am struggling with adjusting the margins of my canvas to ensure equal spacing on both sides without any horizontal scroll bars. Desired Outcome: Equal margin on both sides of canvas without any horizontal scroll bars. Issue: The margin-right property i ...

"Enhancing User Interaction with jQuery: Modifying Attributes on Click

I have the following code snippet: <div id="mtg_card"><a href="#" onclick="someEvent()"><img class="mtg_shop_cart" src="images/shop_cart_green.png" alt="" /></a></div> This code is being looped X number of times within a div ...

Ways to identify when a React child element is overflowing

tl;dr How can I create a component that hides overflow and toggles views with a button? For example, the user can initially see tabs 1, 2, and 3 while tabs 4, 5, and 6 are hidden. Clicking a button will hide tabs 1, 2, and 3, and show tabs 4, 5, and 6 with ...

Showing the values of two distinct select boxes in a URL

Here are both select boxes, the goal is to display selected values from both in the URL. This can be achieved by displaying them like this: e.g www.example.com#135+#140 OR www.example.com#135&140 (The order of values doesn't matter as long as bot ...

Creating a component that surpasses all others

I have a code snippet that contains styling information for two div elements. How can I ensure that my <div id="home"> appears below my <div id="navigate"? Any suggestions? #home { background-color: black; color: grey; text-align: c ...

Dividing a pair of CSS stylesheets on a single HTML page

Currently, I am working on a HTML page that includes multiple javascripts and css files in the header section. <link href="@Url.Content("~/Content/css/main.css")" rel="stylesheet" type="text/css" /> In order to make the website mobile-friendly, I s ...