Update the bootstrap button's value when clicking on it

Looking to change the content of a button upon clicking it - specifically transitioning it to a "block" state where it becomes unclickable, all while displaying a Glyphicon icon.

Here's what I want to include:

<span class="glyphicon glyphicon-saved" aria-hidden="true"></span>

Along with the text "Downloaded" - my goal is to replace the original text and Glyphicon, and I stumbled upon this jQuery snippet that alters the text on click.

<script>
$(document).ready(function(){
$('#download-btn').click(function() {
 $("#download-btn").text('Downloaded');
})
});    
</script>

However, I encountered an issue while trying to include HTML code, as it was displayed as plain text.

Lastly, I aim to apply the style btn-block to the button.

Here is the button before being clicked:

<button id="download-btn" type="button" class="center btn btn-primary">
    <span class="glyphicon glyphicon-save" aria-hidden="true"></span> Download
</button>

After clicking, the jQuery snippet mentioned above changes the text to "Downloaded", yet I'm struggling to understand how to add both style and code to a tag.

Answer №1

Utilizing jQuery:

There exist numerous other jQuery functions for manipulating the DOM.

It's recommended to explore the jQuery API

Answer №2

To change the HTML content inside the selected element, you can use the method .html().

There are multiple ways to disable buttons. One option is to use .attr(), or you can also utilize .prop().

$('#download-btn').click(function() {
   $(this).html('<span class="glyphicon glyphicon-ok"></span> Downloaded').attr('disabled', true); 
});

Check out this Example on JSFiddle

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

The behavior of placing an <a> element within an inline <li> element

I find the HTML / CSS result below to be quite puzzling and unexpected. I am eager to understand the reasoning behind how this is being interpreted. Consider: #nav { list-style-type-none } #nav li { display: inline; } /* make the LI's stack ho ...

Dynamic content in CSS horizontal alignment

In a parent div with fixed width, I have dynamically created divs that I want to distribute horizontally without knowing the exact number of elements. I tried using the "Using inline-block and justified text" technique from a CSS Tricks page but it did not ...

Menu with option to delete next to each selection item

My task is to create a drop-down menu with a delete 'X' option next to each item. This functionality should work even when the drop-down is dynamically populated, without resorting to using a list as an alternative. UPDATE: The icons next to eac ...

Is it possible to optimize the performance of my React and TypeScript project with the help of webpack?

I am working on a massive project that takes 6 to 8 minutes to load when I run npm start. Is there a way to speed up the loading process by first displaying the sign-in page and then loading everything else? ...

My website is experiencing issues with the inner border being transparent and not displaying correctly

I have encountered an issue where the inner border only appears transparent on a single page or JSFiddle, but for some reason it is not working on my website. Can anyone offer any assistance on what might be causing this problem? The border is displaying ...

Conceal a different div unless it includes

Hi everyone, I need help with a filter code snippet: $(".title").not(":contains('" + $("[name=filter]").val() + "')").hide() The issue I'm facing is that the .title class is nested within the .sortAll class along with many other divs. I w ...

Scss - Only one for mobile devices

Just dipping my toes into scss and I've got a quick question. Here's the snippet of scss code I'm working with: .page { max-width: 1200px; position: relative; width: 100%; ul{ background-color: black; width ...

Having trouble with changing the class using Jquery click function

Originally, I had the code in an ASP.Net project, but to troubleshoot, I moved it to a separate web server. However, I am still unable to switch between the tab panes with the buttons. Any assistance in debugging this issue would be greatly appreciated. S ...

Changing HTML5 input type date into a string representation

Here is my PHP code snippet: <?php include 'config.php'; if(isset($_POST['submitbtn'])){ $date = $_POST['datefield']; $newDate = date("Y-m-d", strtotime($date)); $result = mysql_query("Call seat(".$newDate.")"); if($resu ...

What is causing the z-index to not function properly on my elements?

In my current code setup, I have positioned the hero image at the bottom with an overlay on top that contains text and a button. Additionally, there is a navigation bar with a z-index applied. However, I am facing an issue where the button for viewing my r ...

Adding external JSON data to a plain HTML document can be achieved through the process of

I have been experimenting with extracting data from an API in JSON format, but I am struggling to figure out how to convert the JSON tags into HTML elements. You can view a sample of the JSON data here. Does anyone know how to transform this JSON into DI ...

Multi-object retrieval feature in Material Dialog

I am encountering an issue with Material Dialog when confirming the action to "remove row" in a table. Initially, removing from the dialog works fine and deletes a row. However, after closing the dialog and re-calling it for the second time, the removal ac ...

Is there a way to verify the accuracy of the details in Django without having to render the page?

Looking for a solution on how to validate a 10-digit phone number in a registration form created using the Django framework without having to refresh the page and risk losing all the entered data? Seeking advice on improving phone number validation for Dj ...

Switching from a vertical to horizontal tab layout in Angular 4 Material 2 using MD-Gridlist

I'm currently trying to modify the tabbing functionality within an MD-Gridlist so that it tabs horizontally instead of vertically. I've experimented with tab indexes but haven't had any success. My goal is to enable horizontal tabbing throug ...

Is there an alternative to translate3d that I should consider using?

When the code transform: translate3d(0,0,0); is included, it prevents position:fixed; from working. After removing it, I am able to use position:fixed; once again. However, there is now an issue with my navigation bar, as it relied on the transform code to ...

Comparing transition effects: scale, transform, and all

My goal is to apply transition effects to specific transform functions in CSS, such as scale(), while excluding others like translate(). Initially, I attempted the following code snippet: input:focus + label, input:not(:placeholder-shown) + label { tran ...

What is the best way to render JSON information in JSP with JavaScript?

Using Spring MVC, my controller "Book.java" returns a JSON object. I would like to display the content of the JSON object in a table format in a JSP. How can I achieve this? Here is the function in my controller that returns the JSON object: @Controller ...

How can I position an element at the bottom of a page using VueJS and Bootstrap CSS?

https://i.sstatic.net/ojanG.png I am trying to move my footer (Copyright statement) to the bottom of the page. However, it is creating some extra white space beneath the footer. How can I eliminate this additional white space? This issue is occurring in ...

Effortless Numerical Calculation for Trio Input Fields

I am in the process of setting up three numeric input fields that will automatically calculate and display results on the side. I am struggling with this task as I am not familiar with using ajax. Can someone assist me in implementing this functionality us ...

Unusual behavior observed with Chrome image resizing

I've encountered an odd issue with Chrome related to image resizing when the window size changes. When I have Chrome snapped fullscreen in Windows (double-clicking to snap), and then unsnap the window, the images are not scaling correctly back to the ...