Improve company productivity with a Business Account.Sign Up

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 66
  • Last Modified:

HTML DOM structure gets "messed" up after JS function call?

I have back-end engine creating html, resulting in a webpage with frames. So far everything works fine.

A recent addition (javascript function) that changes the background cell of a table in the same frame (called "output", which is the big part of the screen where everything is sent to), works fine, ie does the job BUT after the function call, any click on links from the 'top' frame opens a new tab, instead of loading the link content to the 'output' frame, as it does normally when the new function is not called.

The function that breaks things is: colorTableStat, called with click on an image, like this:
<img src="/images/colorize.png" alt="colorize table" onclick="colorTableStat(''tab11'');colorTableStat(''tab22'');colorTableStat(''tab33'');flip=!flip;" ALIGN=right width=46 height=26/>'              

tab11, tab22, tab33 are ID's on a TD where the actual table with the rows/data is and is being colored correctly. so the coloring function works fine besides it messes up things after it has been called so the links no longer open in the 'output' frame.

the video upload does not work so here is a link to a video version showing what the problem is:

Any idea what might be wrong?
Berhan Karagoez
Berhan Karagoez
  • 6
  • 3
1 Solution
zephyr_hex (Megan)DeveloperCommented:
My first guess would be event propagation.  To test the theory, you could adjust your JS function so that it accepts the event, and then do a stopPropagation();

Here is more on the topic:
Berhan KaragoezCreatorAuthor Commented:
I dunno, I mean I have a similar function that does the same thing with another set of tables and that one does not break the logic, why should another similar function break it?!

I will have to check and test things, will have to get back on this, but I am not happy to invent stuff to make a "bug" stop being a bug. I don't see the logic of manipulating the dom breaking the links in another frame, or making the whole site "forget" this being the 'output' frame.

Read some on the link provided, not sure how to test that one.
I am sending just the id's of the <TD>'s, those are being set on and off with colors. The code is very basic.

I don't get the things said in the link you provide zephyr_hex.
Berhan KaragoezCreatorAuthor Commented:
Again the main 'output' frame works fine before and after the call to the JS function, it is the top frame links that behave differently after calling to the colorTableStat(id) function. Which is very similar to another function colorTable(id), actually a copy of it and adjusted to the columns of this set of tables being manipulated. Those two functions are pretty similar in logic, and I don't understand why one does nothing to the link behaviour (of the top frame) while the other breaks it and forces links now opening to a new tab. it's like the main 'output' frame is somehow forgotten that it exists?!

I don't get that.
Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to and use offer code ‘EXPERTS’ to get 10% off your first purchase.

Berhan KaragoezCreatorAuthor Commented:
AH ok, I found out WHY it happens, so I have fixed it, and this is crazy as F**K.

ok I had :
var stars=0;name=1;pos=2;side=3;games=4;goals=5;assist=6;motm=7;dp=8;avg=9;ngames=11;ngoals=12;nassist=13;nexp=14;cgames=15;cgoals=16;cavg=17;cexp=18;

all in one single line, assuming I was declaring all those variables instead of declaring them individually.

changing it to:
                  var stars=0;
                  var name=1;
                  var pos=2;
                  var side=3;
                  var games=4;
                  var goals=5;
                  var assist=6;
                  var motm=7;
                  var dp=8;
                  var avg=9;
                  var ngames=11;
                  var ngoals=12;
                  var nassist=13;
                  var nexp=14;
                  var cgames=15;
                  var cgoals=16;
                  var cavg=17;
                  var cexp=18;

Fixes it!!!

Looks ugly but I can live with that.

And what I meant to do there actually was:
var stars=0,name=1,pos=2,side=3,games=4,goals=5,assist=6,motm=7,dp=8,avg=9,ngames=11,ngoals=12,nassist=13,nexp=14,cgames=15,cgoals=16,cavg=17,cexp=18;
Berhan KaragoezCreatorAuthor Commented:
Sorry but the selection of "assisted solution" and "best solution" does not work, probably buggy javascript of some kind, I can not close this question...
zephyr_hex (Megan)DeveloperCommented:
You can flag the question for moderation attention and let them know you can't close it.  Also, since my answer was completely down the wrong path, you should just mark (or tell the Mod to mark) your solution as the answer.
zephyr_hex (Megan)DeveloperCommented:
As a side note, I tend to suspect event propagation when odd things happen.  Event propagation can cause iterations of an event to fire, leading to crazy results.  If you're often working in JavaScript, it's important to understand the concept of events "bubbling" up the DOM.  stopPropagation prevents the event from "bubbling" up any further.
Berhan KaragoezCreatorAuthor Commented:
Thanks for your time zephyr_hex!!
Berhan KaragoezCreatorAuthor Commented:
This fixes the original issue.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

  • 6
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now