1

I am not able to change the css properties of a div when calling the onClick function.

<h1 id="hello">hello</h1>

<div id="notification" class="alert alert-dismissible alert-success">
    <button type="button" class="close" data-dismiss="alert">×</button>
    <strong>Well done!</strong> You successfully posted to Facebook!
</div>

<div align="center" class="col-sm-4">
    @using (Html.BeginForm("distShare", null, new { area = "" }))
    {
        <button onclick="facebookButton2()" class="btn btn-primary" type="submit">Share this to Facebook</button>
    }
</div>
function facebookButton2() {
    document.getElementById("notification").style.visibility = visible;
    document.getElementById("notification").style.color = red;
    document.getElementById("hello").style.color = red;
}

The "hello" was simply for testing purposes. I have tried using JQuery and the onSubmit function as well. The notification div starts off as visibility: hidden.

1
  • what is going on between the @ symbol? Commented Apr 26, 2015 at 20:43

3 Answers 3

1

I guess that the values you are passing should be strings, I honestly doubt that you have declared javascript variables called visible and red anywhere in your page:

function facebookButton2() {
    document.getElementById("notification").style.visibility = 'visible';
    document.getElementById("notification").style.color = 'red';
    document.getElementById("hello").style.color = 'red';
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! This was part of the problem XD
0

Change your function as:

function facebookButton2() {
    document.getElementById("notification").setAttribute('style','visibility:visible');
    document.getElementById("notification").setAttribute('style','color:red');
    document.getElementById("hello").setAttribute('style','color:red');
}

See that working here: http://jsbin.com/rosubazuna/1/

Comments

0

Found the problem.

The "distShare" was calling the distShare() method in my controller and that method returned me to a "new" view even though it was the same page. I was essentially refreshing the page. So it was technically working and I just didn't realize it. However, I also did have to change the values to strings as Darin Dimitrov suggested. Thanks for your help!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.