JavaScript Why does my dynamic javascript highlight form break? does google index dynamic javascript content

I've been trying to build a simple html form that highlights text in yellow on a page by wrapping it in a span on keyup of the form (using jquery).

It works fine until I backspace on the keyboard to fully clear the contents of the form, then it stops working. I've created a quick codepen to demonstrate my issue:

http://codepen.io/liamtarpey/pen/KefCx

It's probably a very simple fix but I can't get my head around what's going wrong, does anyone know what the issue is?

I'd really like to use the 'body' or 'html' selector rather than '*' as it affects the head of my page too but I can't get it to work with either of these.

HTML:

<form>
<input type="text" id="searchfor"/>
</form>
<!-- The below is just a test to check the value of the input is being returned -->
<span>Value of form: </span><span id="test"></span>

<div>
  <h3>example text here</h3>
</div>

jQuery:

$("#searchfor").on("keyup change", function() {

  // store value in a variable
  value = this.value;

  // unwrap span from previous search
  $("span[id^='highlightspan']").contents().unwrap();

  // wrap span around inputted text
  $("*").each(function() { 
    if($(this).children().length==0) { 
      $(this).html($(this).html().replace(value, '<span id="highlightspan" style="background:yellow;">' + value + '</span>')); 
    } 
  });

  $("#test").html(value);

});

Answer:1

I am trying to implement a graphQL API, it went well with queries but it's going not that well with mutations: Here is my basic mutation using apollo-client and graphql-tag: import gql from '...

I am trying to implement a graphQL API, it went well with queries but it's going not that well with mutations: Here is my basic mutation using apollo-client and graphql-tag: import gql from '...

  1. graphql syntax error expected name found
  2. graphql syntax error expected name found eof
  3. graphql syntax error unexpected eof
  4. graphql syntax error unterminated string
  5. graphql syntax error unexpected name
  6. graphql syntax error expected $
  7. graphql syntax error expected name
  8. graphql syntax error expected found
  9. graphql syntax error expected name found int
  10. graphql syntax error
  11. graphql message syntax error unexpected eof
  12. magento graphql syntax error unexpected eof
  13. syntax error graphql request expected name
  14. syntax error graphql request

I'm trying to find a way to take a link from one browser and open it in another browser. This could be taking a link from a Firefox tab and opening it in Chrome, or taking a link in a Chrome Incognito ...

I'm trying to find a way to take a link from one browser and open it in another browser. This could be taking a link from a Firefox tab and opening it in Chrome, or taking a link in a Chrome Incognito ...

I am trying to create a secure way for users to log in to and perform certain authorized actions on my custom website. I am trying to have good security without the use of SSL. At login now, this is ...

I am trying to create a secure way for users to log in to and perform certain authorized actions on my custom website. I am trying to have good security without the use of SSL. At login now, this is ...

I am trying to sort array of objects based on an integer property. When using lodash's method _.sortBy() the order is as expected but when I use the built in method it isn't right. Check the snippet ...

I am trying to sort array of objects based on an integer property. When using lodash's method _.sortBy() the order is as expected but when I use the built in method it isn't right. Check the snippet ...

  1. react native array prototype