0

I am making a website and trying to change the value of active car variable which doesn't change even after click on the division the value of activecar remains as .blueimg only even after clicking on the divisions

What is incorrect?

actions.js file

var activecar=".blueimg";
$(".redimg").hide();
$(".greyimg").hide();
$(".silverimg").hide();

$(".red").click(function(){
    hideshow(".redimg",activecar);

});


$(".blue").click(function(){
    hideshow(".blueimg",activecar);

});


$(".grey").click(function(){
    hideshow(".greyimg",activecar);

});


$(".silver").click(function(){
    hideshow(".silverimg",activecar);

});
function hideshow(colour,activecar) {
    console.log("before");
    console.log(activecar);
    $(activecar).hide();
    $(colour).show();
    activecar = colour;
    console.log("After");
    console.log(activecar);

}

This is my index.html file

<!doctype html>
<html lang="en">
<head>

    <title>CollegeDunia</title>
    <link rel="stylesheet" href="styles.css">
</head>
<body>
<img src="./assets/blue.jpg" class="blueimg"/>
<img src="./assets/red.jpg" class="redimg"/>
<img src="./assets/grey.jpg" class="greyimg"/>
<img src="./assets/silver.jpg" class="silverimg"/>

<div>
    <a class="blue">Blue</a>
</div>
<div >
    <a class="grey"> Grey</a>
</div>
<div >
    <a  class="red">Red</a>
</div>
<div >
    <a class="silver">Silver</a>
</div>


<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="actions.js"></script>
</body>
</html>
1
  • The activecar inside hideshow is not the same as the global variable activecar they are not tied to each other. Setting one will not change the other. Commented Sep 16, 2018 at 16:31

1 Answer 1

1

change function's parameter name. It has same name with your global variable.

function hideshow(colour, car) { //activecar changed to car
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.