Change the title of the page according to the title of a division

When a specified element is visible to viewport, the title of the page will change because of the element is visible to viewport, but how can I change the title according to the ‘title’ of a division?

Website for live viewing and testing

(Some of the codes are from the GitHub repo “jQuery.isOnScreen”; I don’t claim the right to say it that it is mine, but i’m trying to use it and modify it for my website, kudos to the original dev :D)

That code works as is, what’s the question?

<!DOCTYPE html>
<meta charset="utf-8">
<style media="screen">
body, html {
  height: 100%;
div#a1 {
  border: 5px solid red;
  margin: auto;
  border-radius: 3px;
div#a2 {
  border: 5px solid black;
  margin: auto;
  border-radius: 3px;
<div id="a1">
  <p> The title is normal, but when you hover down... </p>

<div id="a2" class="target label label-info" title="Article 2 | Prospekt">
  <p> Stackoverflow is an amazing place! Please check your title if someting happened! *something happens magically* </p>

<script type="text/javascript">
// This Gets the Article Title from a Division!

$.fn.is_on_screen = function(){
    var win = $(window);
    var viewport = {
        top : win.scrollTop(),
        left : win.scrollLeft()
    viewport.right = viewport.left + win.width();
    viewport.bottom = + win.height();

    var bounds = this.offset();
    bounds.right = bounds.left + this.outerWidth();
    bounds.bottom = + this.outerHeight();

    return (!(viewport.right < bounds.left || viewport.left > bounds.right || viewport.bottom < || > bounds.bottom));

function updateTitle() {
  if( $('.target').length > 0 ) { // if target element exists in DOM
    if( $('.target').is_on_screen() ) { // if target element is visible on screen after DOM loaded
        document.title = "An Article"; // show this if visible
    } else {
          document.title = "Prospekt | A Gaming Community"; // show this if NOT visible



This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.