если текст span (внутри iframe) равен текстовому блоку div - PullRequest
0 голосов
/ 10 января 2020

Как это может работать, если элемент span находится внутри iframe? код ниже работает

  • ** Как это может работать, если элемент span находится внутри iframe? *

$(document).ready(function() {
  if ($("span#lblConfirmacao").text() == "Quero mudar para corrente") {
    document.getElementById("b-conta").style.display = "block"
  } else {
    document.getElementById("a-conta").style.display = "block"
  }
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>

<div style="margin-top: 0rem; width: 70%;"> 
 <label id="lblChk" title="Marque para confirmar a alteração">
  <input id="chk" name="chk-prospects" type="checkbox">
   <span id="lblConfirmacao">Quero mudar para corrente</span>
 </label>
</div>



<div id="b-conta" style="display:none;">
  <p style="font-size: 13px;">
    <strong>Atenção:</strong> A partir da alteração do modelo.
  </p>
</div>
<div id="a-conta" style="display:none;">
  <p style="font-size: 13px; color:#C3C;">
    <strong>Atenção:</strong> Nesse tipo de modelo.
  </p>
</div>

1 Ответ

0 голосов
/ 10 января 2020

Я хочу получить текст внутри de span, который находится внутри iframe

$(document).ready(function() {
  var iframe = document.getElementById("myFrame");
  var elmnt = // iframe.contentWindow.document.getElementsById("#lblConfirmacao")[0];
    if (elmnt == "Quero mudar para liquidação usando minha conta corrente") {
      document.getElementById("bra-conta").style.display = "block";
    } else {
      document.getElementById("agora-conta").style.display = "block";
    }
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>


<iframe src="" id="myFrame" name="myFrame" width="100%" height="400" frameborder="0" scrolling="no">
<div style="width: 70%; margin-top: 0rem;">
<label title="Marque para confirmar a alteração" class="custom-checkbox" id="lblChk">
<input name="chk-prospects" id="chk" type="checkbox">
<span id="lblConfirmacao">Quero mudar para liquidação usando minha conta corrente</span>
</label>
</div>
</iframe>

<div id="br-conta" style="display:none;">
  <p style="line-height: 18px; font-size: 13px; margin-right: 3%; margin-left:3%;"><strong>Atenção:</strong> A partir da alteração do modelo bra.</p>
</div>
<div id="agora-conta" style="display:none;">
  <p style="line-height: 18px; font-size: 13px; margin-right: 3%; margin-left:3%; color:#C3C;"><strong>Atenção:</strong> Nesse tipo de modelo agora.</p>
</div>
...