0

Good Morning,

I was trying to get the class "mk-flex-slide" in a WordPress-Theme open in a new window (target="_blank"), because this plugin has no function to add it. what am I doing wrong?

This is the site: http://heilpflanzen.wiki/loewenzahn-pusteblume/#4
just scroll down a few px to this pic (the sliding pics should open on click in a new window): enter image description here

I tried this code:

window.onload = function(){
var anchors = document.getElementsByClassName('flex-active-slide').getElementsByTagName('a');
for (var i=0; i<anchors.length; i++){
anchors[i].setAttribute('target', '_blank');
 }
}
Krystian
  • 887
  • 5
  • 21
  • 52

1 Answers1

1

getElementsByClassName() returns a list, and the list doesn't have a getElementsByTagName() method. Try document.querySelectorAll('flex-active-slide a') instead:

window.onload = function(){
  var anchors = document.querySelectorAll('flex-active-slide a');
  for (var i=0; i<anchors.length; i++){
    anchors[i].setAttribute('target', '_blank');
  }
}
nnnnnn
  • 147,572
  • 30
  • 200
  • 241
  • Thanks for the quick answer, but unfortunately it does not work. May I chose the wrong class? – Krystian Aug 30 '16 at 07:30
  • 1
    Perhaps. Your description mentions a class `"mk-flex-slide"`, but your code has a class `"flex-active-slide"`, so perhaps you should be using the `mk` one. But note that I was only going off the information in your question, and you didn't show your HTML - I didn't follow your link to an external site. – nnnnnn Aug 30 '16 at 07:36