JQuery - Unable to replace the old name with the new one

Hello, I am currently working on jQuery. I have a code snippet to update the project name. It includes an input field and a save button. The process involves fetching the current project name, displaying it in the input field, allowing for edits, and then updating the project name upon clicking the save button. Unfortunately, I'm encountering difficulties with this process. Kindly assist me in resolving this issue. Thank you in advance.


                $(document).ready(function() {
                    $(".detail-wrp").on("click", function() {
                      let inputVal = $(".prjt-nme", this).text();
                      $(".prjt-nme", this).hide();
                      $(".update-wrp", this).show();
                      $(".detail-input", this).val(inputVal).focus().select();
                      return false;
                    });
                    $(".detail-save-btn").on("click", function() {
                      $(".prjt-nme").css({
                        "display": "block"
                      });
                      $(".update-wrp").css({
                        "display": "none"
                      });
                      let pk = $(this).parents(".detail-wrp").find(".detail-input").val();
                      $(this).parents(".detail-wrp").find(".prjt-nme").text(pk);
                    });
                });
            

                .general-settings>div {
                    display: flex;
                    padding: 6px 10px 6px 10px;
                    width: 100%;
                    cursor: pointer;
                }

                /* More CSS styles go here */

            

                <meta charset="utf-8">
                <meta name="viewport" content="width=device-width, initial-scale=1">
                <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css">
                <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
                <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script>
                <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
                <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.13/css/all.css">

                <!-- Your HTML code goes here -->
            

Answer №1

Make sure to update your edit click functionality below:

    $(".prjt-nme").on("click", function() {
    let inputVal = $(this).text();
    $(this).hide();
    $(this).next().show();
    $(".detail-input", this).val(inputVal).focus().select();
    return false;
    });

Additionally, don't forget to place the project name within a <span> tag and update your Save function to show the Pencil icon again.

<div class="prjt-nme"><span>abcdefgh.comA1</span> <a href="#" class="float-right prjt-edit-icon"><i class="fas fa-pencil-alt"></i></a></div> //html 

$(this).parents(".detail-wrp").find(".prjt-nme > span").html(pk); //in save function

Answer №2

$(".update-wrp", this).display();

It is wise to disable the display function in the code above after it has been used, as it will continue to keep showing until another command instructs it otherwise. By inserting a few .focus commands, you can manage its behavior, or alternatively, you could simply comment it out and then reevaluate the functionality.

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

Issue with JQuery form submission causing controller method not to be executed

I am facing an issue with two click methods in my JavaScript code. Method 1 is successfully hitting the controller method, but when I try to trigger Method 2 by clicking on a button, it does not seem to call the controller. I have tried various solutions ...

The output of new Date() varies between app.js and ejs

app.get("/test",function(req,res){ var d = new Date(); res.send(d); }); When I access mydomain/test, it displays the output "2019-03-19T04:50:47.710Z" which is in UTC. app.get("/testejs",function(req,res){ res.render("testejs");}); Below is the content ...

Struggling to make Bootstrap 3 appear professional when printed

Struggling to get my printing to look good with bootstrap 3. Any suggestions on how to improve it? Desired outcome: Current look: Here is my code: <div class="row page-header"> <div class="col-xs-12"> <div class="col-md-2"> ...

Incorporating <span> elements into a comma-separated list using Jquery on every other item

When I receive a comma-separated list of items from a database and insert them into a table cell, I want to apply alternating styles to make it easier for users to distinguish between them. For example: foo, bar, mon, key, base, ball I'm looking to ...

The second attempt at an AJAX call is unsuccessful

I am currently developing a form that displays database results based on two entries: Automarke (brand) and Modell (model). You can view the entries here. The Modell dropdown dynamically changes based on the selected Automarke. Here is the code snippet I ...

What is the method for altering the appearance of grid columns with javascript?

What modifications do I need to make in JTML and Javascript? var opac; function checkfun() { opac=(Array.from(document.querySelectorAll('input[type="checkbox"]')) .filter((checkbox)=>checkbo ...

Combining jsTree with Treemodel for Enhanced Functionality

As someone new to Javascript, I'm looking for guidance on integrating jsTree on the front end with backend services in node.js. The backend utilizes the Treemodel library (http://jnuno.com/tree-model-js/) and includes additional functions like: funct ...

Introducing fresh background images for every MDlite card

Hello StackOverflow community! I am a long-time user and this is my first post. I need some help with adding two MDlite cards to my website, each with a different background image. However, I'm encountering an issue where the last-declared background ...

Enhance your Bootstrap navigation menu with eye-catching hover effects

Hey everyone, I'm a beginner in web development and I'm attempting to incorporate a hover effect into my navigation menu. I want it to look like the first example in this link: https://codepen.io/Calloumi/pen/vndlH I've tried to replicate t ...

Tips for managing the creation of dynamic Bootstrap cards using jQuery

I am embarking on the creation of an entertaining game where users can input their name and email address. Upon clicking the "Add" button, a new card will be generated containing a form with checkboxes labeled "One" and "Two". Depending on the selection of ...

Error: This value is not a valid HTMLInputElement type (Google Maps)

When attempting to create a basic autocomplete field for Google Map places, I encountered the following error message despite having an HtmlInputElement as my field InvalidValueError: not an instance of HTMLInputElement Here is the HTML code: <inpu ...

Real-time PHP input field updating as values are typed

Hey there, I'm working on a little PHP calculator for myself and I'm curious if it's possible to have the answer update instantly after I input the values. Any ideas? Thanks in advance! <?php if (isset($_POST['valuea'])) ...

Preventing the addition of hash tags to the URL by the anything slider

Why does the Anything Slider add hash tags like #&panel1-1 to the end of the URL? I attempted using hashtags:false but it was unsuccessful. Are there alternative methods to prevent it from creating these hashtags? ...

Difficulty integrating custom CSS with Bootstrap framework

I attempted to incorporate a custom CSS file with my Bootstrap code, but unfortunately it does not seem to be functioning properly. <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta htt ...

PHP script redirects to its own URL successfully, but the functionality fails when triggered by CRON

I am facing an issue with a program that calls itself iteratively. redirect($_SERVER["PHP_SELF"]); function redirect($url,$seconds=0) { $html="<html><head><meta http-equiv='refresh' content='$seconds; URL=$url'>< ...

The JavaScript code that functions properly in Codepen is not functioning on my HTML page

Can you help me understand why this code is working fine in CodePen, but not on my HTML page? I'm unable to identify the error that may have occurred. Any assistance would be greatly appreciated! I suspect there's an issue with connecting some jQ ...

The CSS class is mistakenly being applied to the entire page instead of just the specific div it was

Here is the HTML code I am working with: <!DOCTYPE html> <head> <title></title> {% load staticfiles %} <link rel="stylesheet" type="text/css" href="{% static 'portfolio/mystyle.css' %}" /> <link rel="styl ...

Modernized Style - Additional Scrolling Feature for List Element

I've implemented code from Google's Material Design website for my project: https://material.io/components/web/catalog/lists/ Although it works well, the issue arises when more list entries are added and I have to scroll down to view them. The p ...

ASP.NET Expandable Navigation Bar

I'm struggling to create a collapsible navigation bar for my website that works well on mobile devices. Here's the code for my navigation bar: <div style="padding-bottom: 50px;"> <header id="main-header"> <div ...

Struggling with getting cards to display horizontally using React bootstrapping

I'm currently in the process of creating a portfolio website using React Bootstrapping. I'm encountering an issue where the card components I'm using to display images appear vertically instead of horizontally. I've attempted to trouble ...