slides = document.getElementsByClassName("mySlides");
What I need is that through a function I can change "myslides" to "mySlides1"
slides = document.getElementsByClassName("mySlides");
What I need is that through a function I can change "myslides" to "mySlides1"
Here is an example of how you can do it. Greetings!
//Obtengo el elemento
var elem =$("#input1");
//Muestro el nombre actual
console.log(elem.attr("name"))
//Asigno el nuevo nombre
elem.attr("name","nombre2");
//Verifico que el cambio se haya realizado.
console.log($("#input1").attr("name"))
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input id="input1" type="text" name="nombre1" />
To change the name of your class you can use TUDIV.className.replace(/ *\bmySlides\b/g, "mySlides1");
where TUDIV
is the element per id and the replace()
use it to change the name of the previous class in this case mySlides
per mySlides1
, what you have around in the replace / * \ b and \ b / g is a rule that is set to work in all browsers such as Internet Explorer.
I gave you a simple example where the class mySlides
has a red border and when the class is changed to mySlides1
changes to blue:
document.getElementById("cambiar-clase").addEventListener("click", function() {
slides = document.getElementById("div");
slides.className = slides.className.replace(/ *\bmySlides\b/g, "mySlides1");
});
.mySlides{
border:1px solid red;
height:50px;
}
.mySlides1{
border:1px solid blue;
height:50px;
}
<button id="cambiar-clase">Cambiar nombre de clase</button>
<div id="div" class="mySlides"><div>