• Register
1 vote
47 views

Problem :

If I try to click on a particular class, the alert pops up. If I confirm, then it should change the background colour of that element I have clicked on and it should change the background colour of that existing element. If I wanted to do this straight away after the click on the element I could have just used written the code as below :

$(this).css("background-color", "red");

But as I want to do it after that alert, I am unable to use this logic and I don't know how to get that clicked class.

Please find below my code :

$( ".thumbs" ).on("click", ".thumb-wrapper", function() {

        var bcprodId = $( ".featured-wrapper" ).data("bcprodid");

        var bcprodName = $(this).data("name");

        swal({

                bctitle: 'Set Featured image',

                bctext: "Are you sure you want to change it?",

                bctype: 'warning',

                bcshowCancelButton: true,

                bcconfirmButtonColor: '#3085d6',

                bccancelButtonColor: '#d33',

                bcconfirmButtonText: 'Yes, change it!'

            }).then(function () {

                swal(

                    'Changed it!',

                    'Featured image changed it.',

                    'Success'

                )

                    $.ajax({

                        bcurl: 'functions/changed-featured-img.php',

                        bctype: 'POST',

                        bcdata: {

                            bcprodId: bcprodId,

                            bcprodName: bcprodName

                        },

                    })

                    .done(function (bcdata) {

                        $( ".featured-wrapper" ).css("background-color", "white");

                   // need to change the clicked class background to red.

                    })

                    .fail(function (jqXHR, textStatus, errorThrown) {

                        console.log(textStatus + ': ' + errorThrown);

                        console.warn(jqXHR.responseText);

                });

        })

            .catch(swal.noop)

    });

6 5 3
7,540 points

Please log in or register to answer this question.

1 Answer

0 votes

Solution :

Please save your clicked element to a variable just before calling the swal():

var $this = $(this);

In your later function please use as below:

$this.css("background-color", "red");
9 7 4
38,600 points

Related questions

0 votes
1 answer 42 views
42 views
I need to change the background color on button click applyig Javascript.
asked Sep 25, 2020 Daniel Anderson 4k points
0 votes
1 answer 9 views
9 views
I am new to this. I was doing that but I got into some problems.
asked Dec 3, 2020 TeamScript 13.5k points
0 votes
1 answer 15 views
15 views
We need to open a page as pop up window in a button click. Can anyone help me here?
asked Sep 16, 2020 Daniel Anderson 4k points
0 votes
1 answer 57 views
57 views
Problem : I have written two different types of sticky menus for two different pages. Following is the error Inside the anonymous function, use jquery to select the footer div. it has an id of 'footer'. Following is the code for both Menus. $(document).ready(function () { ... the bottom doesn't work because the second line of code var contentNav = $('.content-nav').offset().top; fires a error .
asked Nov 19, 2019 peterlaw 6.9k points
0 votes
1 answer 261 views
261 views
Problem : Facing following chrome error error in event handler for (unknown): typeerror: cannot read property 'indexof' of undefined
asked Nov 16, 2019 peterlaw 6.9k points
0 votes
1 answer 3 views
3 views
Problem: which of the following is correct to set “black” color as background of page? I am trying to change the background color for the whole page in Angular(would use body, or html tag when working without framework). and I can't find the best practice for this, I want it to be within the framework if possible since I am building an application for years to come.
asked 1 day ago Umar Ahmad 2.1k points
0 votes
1 answer 67 views
67 views
Problem: I am new in programming and my syntax is not good, can anyone provide the right query to find? Select the code below that uses CSS to configure a background color of #eaeaea for a web page. a. body { background-color:#eaeaea} b. document {background-page:#eaeaea} c. body {bgcolor:#eaeaea} d. None of the Above
asked Feb 19, 2020 maddi86 5.4k points
0 votes
1 answer 26 views
26 views
I need to disable refresh button of browser applying Jquery.
asked Sep 25, 2020 Daniel Anderson 4k points
0 votes
1 answer 12 views
0 votes
1 answer 16 views
16 views
I am new to this. I just want to know how to do that?
asked Dec 3, 2020 TeamScript 13.5k points