How to check if a value isn't changed in between <span> tag

uhbc

The page looks like:

<html>
  <span id="somespan">1000</span>
</html>

The value of somespan increases every 1 or 2 minutes.

With Javascript/JQuery, how can I check if the value is same or increased every 5 minutes.

I mean at 16:00 the value is 1000 and 2 minutes later so at 16:02 its 1200.
How can I check if its changed.

I wanna make something like:

var somespan = $("#somespan").text();

if(somespan isnt changed) {
  #console.log('still same.')    
}

The platform i will use this code is Google Chrome -> Tampermonkey

Pilan

You can implement a MutationObserver, but this will do as well.

var current_value = null;
setInterval( function() {
  if (current_value != null) {
    if (current_value != $('#somespan').text()) {
      console.log('Value has changed!');
    }
  }
  current_value = $('#somespan').text();
}, 1000 );

// For testing only
$('input').on('input', function() {
  $('#somespan').text( $(this).val() );
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<span id="somespan">1000</span>

<!-- For testing only -->
<br/>
<input type="text" value="1000">

via MutationObserver (no polling required)

const observer = new MutationObserver(function(mutations) {
  for (const mutation of mutations) {
    if (mutation.type === 'childList') {
      console.log('Value has changed!')
    }
  }
});

observer.observe(document.querySelector('#somespan'), {childList: true});

// For testing only
document.querySelector('input').addEventListener('input', function() {
  document.querySelector('#somespan').innerHTML = this.value;
});
<span id="somespan">1000</span>

<!-- For testing only -->
<br/>
<input type="text" value="1000">

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to write a value in span tag?

How can I change the value between <span> tag </span> using jQuery?

How to check if value is in dictionary or why it isn't working?

Can't display content in between span tag

Python how to check if value changed

check if value is changed between group of transactions

SQL query to check if a value isn't present

How to obtain value from span tag in selenium

Reference Assignment in Python - Why isn't the value changed?

scope variable after select file isn't changed its value

Python, how to check if value changed in mqtt

jQuery Isn't Updating Span

How to get a value between a span with DOM

How to alert a text between a Span Tag using Javascript?

How to display text in a span tag based on the value of input field

How to get rid of : Warning: Invalid value for prop `settaskstatus` on <span> tag

How to get each value inside <li> with <span> tag BeautifulSoup

how to select a tree node span tag value in python selenium webdriver?

How to change img src value using span tag

How to write if first child of an element isn't an a tag in javascript?

Ionic scope value isn't updated navigate between $state

Groovy: How to check multiple tag value in xml?

How to check if xml tag value is none in python

How to check that the object isn't the last and how to handle it if it is?

Calculate percentage of a value in a span tag

Get a value of span tag HTML

Replace value in a span tag with percentage

Visibility of activityIndicator isn't changed after changing the value of variable which is bind with animating props

pass value from span tag to input tag