I was advised not to use any properties inside <tr> tags because it can create problems in some browsers. Is that really so?

Dani AI

Generated

Short answer: HTML allows attributes (including event attributes) on <tr>, but historically some browsers showed inconsistent behavior for inline event handlers on rows. That matches 's experience — visual styling on <tr> is fine, but putting onEvent handlers there sometimes caused cross‑browser quirks. The HTML spec and MDN show <tr> supports the usual global attributes, but modern best practice avoids inline handlers for reliability and maintainability (MDN: tr element).

Prefer these patterns:

  • Use CSS for presentation (avoid deprecated attributes like bgcolor/align).
  • Use event delegation on the table or tbody instead of many inline handlers on rows or cells. This is more robust and faster across browsers.

Example (event delegation):

const tbody = document.querySelector('table#myTable tbody');

tbody.addEventListener('click', (e) => {
  const row = e.target.closest('tr');
  if (!row) return;
  // handle row click
  row.classList.toggle('is-selected');
});

Accessibility/caveats: if rows are actionable, put an actual interactive control (button/link) in a cell, or explicitly make rows focusable with tabindex="0" and handle keyboard events. Test behavior across target browsers and devices as suggested. For details on attributes and event handling see the MDN docs linked above and the HTML spec for tables.

Recommended Answers

All 2 Replies

one way to find out..is to create a page and use that <tr> tags..and test your page in different browsers..check for any difference.. :O) maybe experts around here can give you a better explanation
Goodluck!

We find that there are <onEvent> properties that may fail in <tr> between browsers, we put the <onEvent> handlers in the <td> instead,
visual styling seems to work with every thing

per cguan's advice, this link will let you check out your code in browsers (all of them) to which you do not have access.
It provides screen dumps of browser/os combination

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.