Using jQuery to replace tags within an array?

82
February 25, 2018, at 12:29 PM

I am new to Javascript and JQuery and I am trying to replace all my tags with upon first click, and then replace with on the second click, and so forth.

Basically just cycling through them so on each click I have a 3d rendered box or sphere. I tried to run it with this code however it does not work.

When I checked the console, only the lines were getting logged, so it doesn't seem to be replacing them correctly. I need to keep the tags within each preserved as I work.

var counter = 0;
var myArr = ["a-sphere", "a-box"];
$("#targeted").click(function() {
  if(counter == myArr.length) counter = 0;
  $(myArr[counter]).replaceWith(function() {
    var myString = "<" + myArr[counter] + ">" + $(this).html() + "</" + myArr[counter] + ">";
    console.log(myString + counter);
    return myString;
  });
  counter++;
});
READ ALSO
Dynamic search form using javascript for Django project

Dynamic search form using javascript for Django project

I am trying to create a search form using jquery for Django using following tasks to do:

65
Trying to convert jQuery calls to knockout.js

Trying to convert jQuery calls to knockout.js

I have some code that I need to convert from jQuery calls to knockoutjs syntax

76
crossfade effect not working properly

crossfade effect not working properly

i copied this code from codepenio to add a crossfade effect to my site's background images

44
Is there a css/javascript property for when a div is selected in the url?

Is there a css/javascript property for when a div is selected in the url?

For example, if I have the URL examplecom/#foo, then styling is applied to the div foo

43