0

Here, Why my code is not working in IE. My code is working for all browser.there is no issue. But when I run my project on IE its find error.

And also my jquery class and insertadjacentHTMl not working.

main issue i find in this code.

$("[type=slideshow] section").addClass('hide');
		for(let ele of Array.from($("[type=slideshow]"))){
			$(ele).children("section:first").removeClass("hide").addClass('active');
		}

Here, is my code please review it where is error .

//Code for Slideshow

var divSlide = document.querySelectorAll('#slide');

var myNodeList = divSlide.length;
let slideNo = 1;

for(var i = 0; i < myNodeList; i++) {
	var type = divSlide[i].getAttribute("type");
	if (type == "timeline") {

	} else if (type == "slideshow") {
		var timeline = divSlide[i];     
		let sliderData = timeline.getElementsByTagName("section");
		
		$("[type=slideshow] section").addClass('hide');
		for(let ele of Array.from($("[type=slideshow]"))){
			$(ele).children("section:first").removeClass("hide").addClass('active');
		}

		timeline.insertAdjacentHTML("afterbegin",'<a class="left prev color_arrow carousel-control" href="#myCarousel" data-slide="prev"><span class="glyphicon glyphicon-chevron-left"></span><span class="sr-only">Previous</span></a>');

		timeline.insertAdjacentHTML('afterbegin','<a class="right next color_arrows  carousel-control" href="#myCarousel"  data-slide="next"><span class="glyphicon glyphicon-chevron-right"></span><span class="sr-only">Next</span></a>');
	}
}

$(document).on ('click','.prev',function() {
	let select = $(this).parent();
	let totChild = select.children("section");
	for(let i=0;i<totChild.length;i++){
		if(totChild[i].getAttribute('class').indexOf('active')!=-1){
			slideNo=i+1;
		}
	}
	totChild.children('br').remove();
	let current = select.children('.active');
	let prevEl = current.prev('section');
	
	if(slideNo === totChild.length || slideNo > 1){
		select.children(".next").show();
		if(prevEl.length !== 1){
			prevEl = current.prev().prev();
			current.removeClass('active');
			current.addClass('hide');

			prevEl.addClass('active');
			prevEl.addClass('animated');
			prevEl.addClass('fadeInLeft');
			prevEl.removeClass('hide');
		}
	} else {
		select.children(".prev").hide();
	}
});
$(document).on ('click','.next',function() {
	let select = $(this).parent();
	let totChild = select.children("section");
	for(let i=0;i<totChild.length;i++){
		if(totChild[i].getAttribute('class').indexOf('active')!=-1){
			slideNo=i+1;
		}
	}
	
	totChild.children('br').remove();
	let current = select.children('.active');
	let prevEl = current.next('section');
	if(slideNo ===1 || slideNo < totChild.length){
		
		select.children(".prev").show();
		if(prevEl.length !== 1){
			prevEl = current.next().next();
			current.removeClass('active');
			current.addClass('hide');
			prevEl.addClass('animated');
			prevEl.addClass('fadeInRight');
			prevEl.addClass('active');
			prevEl.removeClass('hide');
		}
	} else {
		select.children(".next").hide();
	}
});

8
  • What exactly is the error on IE? Commented Apr 9, 2018 at 8:47
  • : Expected ';' this is show in console.log Commented Apr 9, 2018 at 8:47
  • That's because for..of is completely unsupported in IE: developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… Commented Apr 9, 2018 at 8:49
  • Why not iterate $("[type=slideshow]") using jquery's each? Commented Apr 9, 2018 at 8:50
  • @gurvinder372 because i have 4 div everything same except it type= timeline and slidehsow and i loop over all section inside div or type div. so i use each $("[type=slideshow]"). give me some suggestion gurvinder pajji. Commented Apr 9, 2018 at 8:53

1 Answer 1

1

for-of is not supported on IE. You can replace your for-of-loop with jquery's each as

$("[type=slideshow] section").addClass('hide');
$("[type=slideshow]").each( function(i,ele){ //i is the index and ele is the element in iteration
   $(ele).children("section:first").removeClass("hide").addClass('active');
});

Also, no need to mix jquery with javascript's querySelector and looping over results using for-loop.

When using # based selector #slide as in this line

var divSlide = document.querySelectorAll('#slide');

It is only going to give one result, simply use

timeline = $( "#slide" )[0];

No need for outer for-loop and if-condition.

Sign up to request clarification or add additional context in comments.

1 Comment

Sure, Glad to help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.