1

Tenho esta div abaixo, nomeadamente com id e tendo dentro da mesma os elementos p seguido a(âncora):

var vid = document.getElementById('player');

var link = document.getElementById('lista').getElementsByTagName('a');

var el = document.getElementById('lista').getElementsByTagName('p');

var src0 = vid.src;

var href0 = link.href;

var fonte = [
	"https://sites.google.com/site/mplayerplugin/repositorio/animais_cantando.webm",
	"https://sites.google.com/site/mplayerplugin/repositorio/equipment_these_days.webm",
	"https://sites.google.com/site/mplayerplugin/repositorio/peck_pocketed.webm"
],
    clone = [
	"https://sites.google.com/site/mplayerplugin/repositorio/animais_cantando.webm",
	"https://sites.google.com/site/mplayerplugin/repositorio/equipment_these_days.webm",
	"https://sites.google.com/site/mplayerplugin/repositorio/peck_pocketed.webm"
];

    function proximo() {
    	if (fonte.length === 0) {
        	fonte = clone.slice(0);
    	}
    	var indice = fonte.splice(0, 1);
    	vid.src = indice;
    	vid.autoplay = indice;
	}
window.setInterval(function() {
    	var seg = vid.duration - vid.currentTime;

    	if ((seg - 1) < 0)

	for (var i = 0; i < el.length; i++) {

	if(src0 == href0) // comparar se o atributo src no elemento video e igual a do atributo href

	el[i].outerHTML = '';

	delete el[i].item(0);

		proximo();

	break;
		}
	}, 1000);

proximo();
<video id="player" preload controls></video>

<hr>

<div id='lista'>
	    <p><a href="https://sites.google.com/site/mplayerplugin/repositorio/animais_cantando.webm">Animais cantando</a></p>
	    <p><a href="https://sites.google.com/site/mplayerplugin/repositorio/equipment_these_days.webm">Equipment these days</a></p>
	    <p><a href="https://sites.google.com/site/mplayerplugin/repositorio/peck_pocketed.webm">Peck Pocketed</a></p>
</div>

Bom, observe bem o meu código-fonte e note que estou fazendo isso automaticamente, sem clicar diretamente no link.

1 Resposta 1

1

Usa el[i].parentNode.removeChild(el[i]); em vez de delete el[i].item(0);

var vid = document.getElementById('player');
var link = document.getElementById('lista').getElementsByTagName('a');
var el = document.getElementById('lista').getElementsByTagName('p');

var src0 = vid.src;
var href0 = link.href;
var fonte = [
  "https://sites.google.com/site/mplayerplugin/repositorio/animais_cantando.webm",
  "https://sites.google.com/site/mplayerplugin/repositorio/equipment_these_days.webm",
  "https://sites.google.com/site/mplayerplugin/repositorio/peck_pocketed.webm"
];
var clone = fonte.slice();

function proximo() {
  if (fonte.length === 0) {
    fonte = clone.slice(0);
  }
  var indice = fonte.splice(0, 1);
  vid.src = indice;
  vid.autoplay = indice;
}
window.setInterval(function() {
  var seg = vid.duration - vid.currentTime;
  if ((seg - 1) < 0)
    for (var i = 0; i < el.length; i++) {
      if (src0 == href0) // comparar se o atributo src no elemento video e igual a do atributo href
        el[i].outerHTML = '';
      el[i].parentNode.removeChild(el[i]);
      proximo();
      break;
    }
}, 1000);

proximo();
<video id="player" preload controls></video>
<hr>
<div id='lista'>
  <p><a href="https://sites.google.com/site/mplayerplugin/repositorio/animais_cantando.webm">Animais cantando</a></p>
  <p><a href="https://sites.google.com/site/mplayerplugin/repositorio/equipment_these_days.webm">Equipment these days</a></p>
  <p><a href="https://sites.google.com/site/mplayerplugin/repositorio/peck_pocketed.webm">Peck Pocketed</a></p>
</div>

2
  • Parece que funcionou com seu método aplicado! Era apenas um detalhe que havia ignorado usar el[i].parentNode.removeChild(el[i]); em vez de delete el[i].item(0);, pois o delete el[i].item(0); tornaria-se Cross-browser. Mas infelizmente pra isso nao deu certo :( 2/04/2017 às 19:06
  • @DiegoHenrique delete el[i].item(0); remove o elemento da lista que o . getElementsByTagName dá, mas não remove da página. Para remover da página tens de usar o método . removeChild()
    – Sergio
    2/04/2017 às 19:08

Você deve fazer log-in para responder a esta pergunta.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .