cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X

Edit CSS Styles with JavaScript

Jonny
8-Gravel

Edit CSS Styles with JavaScript

Hello, 

 

I tried to cange the CSS Style with JavaScipt code but it does not work. What is wrong?

 

$scope.ShowClass = function() {
    document.getElementById('classname').style.display = "block";
}

$scope.HideClass = function() {
    document.getElementById('classname').style.display = "none";
}

 

1 REPLY 1
ClayHelberg
17-Peridot
(To:Jonny)

Unfortunately, stylesheets don't work that way. The most direct approach is probably to identify the desired elements and modify their styles directly, something like this:

 

$scope.ShowClass = function () {

    var elems = document.getElementsByClassName('classname');

    for (var e in elems) {

        elems[e].style.display = "block";

    }

}

 

and similar for $scope.HideClass()

 

If you really need to modify the class style rules, rather than just changing the styling of affected elements, you might find some useful information here:
https://www.quirksmode.org/dom/changess.html

--Clay

Top Tags