saiful saiful - 24 days ago 6
jQuery Question

select an element between 2 element and replace

Hello I want to replace the word 'Register' to 'Hello' right after node

The problem is the word 'Register' is not inside any separate element thats why I can't select with any selector and edit it. and I can't wrap it with any selector either cause the html is generated dynamically by php , and I can't edit php codes thats why I need jquery help.

<div id="register_portion">
<h3>Not registered? No problem!</h3>
Register <!-- I want to change this text -->
<div class="tml tml-register" id="theme-my-login1">
<p class="message">Please register now.</p>
<form name="registerform" id="registerform1"
action="/login-now/?pending=activation&amp;instance=1"
method="post">
form html...
</form>
</div>
</div>

Answer

You need to get the following sibling of h3 element, Use get() to get the underlying DOM element then using nextSibling property target the node, then you can use nodeValue to set its text.

$("#register_portion h3").get(0).nextSibling.nodeValue = "Hello";
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div id="register_portion">
  <h3>Not registered? No problem!</h3>
  Register
  <!-- I want to change this text -->
  <div class="tml tml-register" id="theme-my-login1">
    <p class="message">Please register now.</p>
    <form name="registerform" id="registerform1" action="/login-now/?pending=activation&amp;instance=1" method="post">
      form html...
    </form>
  </div>
</div>