Reputation: 3062
I have an Angular 4 app that includes a "/" for every .inner-page class in a html element.
For example:
<div _ngcontent-c0="" class="inner-page /login">
<div _ngcontent-c0="" class="inner-page /register">
I want to remove the "/" character so it should look like:
<div _ngcontent-c0="" class="inner-page login">
<div _ngcontent-c0="" class="inner-page register">
Any help is appreciated. Thanks.
Upvotes: 0
Views: 191
Reputation: 8752
Split (.split()
) the class attribute (.attr()
) values by the character in question then rejoin (.join()
) them.
Code Snippet Demonstration:
$('.inner-page').each(function(){
var elClass = $(this).attr('class').split(' /').join(' ');
console.log(elClass);
$(this).attr('class', elClass);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div _ngcontent-c0="" class="inner-page /login">Login</div>
<div _ngcontent-c0="" class="inner-page /register">Register</div>
Reference:
.split()
Ref - Javascript MDN.attr()
Ref - jQuery API.join()
Ref - Javascript MDNUpvotes: 2
Reputation: 3450
Try the following code :
var value;
$(document).ready(function(){
$(".inner-page").each(function() {
value = $(this).attr("class").replace("/", "");
$(this).attr("class", value);
});
});
Upvotes: 1