timkl
timkl

Reputation: 3339

Is it bad practice to manipulate HTML content with JavaScript?

I'm currently working on a project where we use a half-baked CMS. Parts of the site, controlled by the CMS, is not editable in the CMS backend. So the company that delivers the CMS suggests that we use jQuery to manipulate the HTML content on these pages.

To me this is a bad idea - mainly because I strive to separate content, design & functionality.

This is a philosophy that has served me well in the past - I find that it's easier to version a site to various platforms and achieve a good, accessible website if I follow these principles.

But I'm looking for more ammunition, e.g. what does this do to SEO? Can Google's spiders access the manipulated content?

Is there other reasons why it's bad practice to manipulate HTML content with JavaScript?

Upvotes: 1

Views: 424

Answers (4)

ZenMaster
ZenMaster

Reputation: 12742

It's a very fine line to walk, but I wouldn't go as far as to say that manipulation of HTML content (and by that I mean layout and styling) is a bad practice. This is the MO of the web today, otherwise your dynamic content, all these sliders and carousels and whatnot, would be limited to CSS manipulations only.

Your problem is different from manipulating HTML with JS. Your problem is that you manipulat a 3rd party HTML content. If tomorrow they change <span> to <div> or one ID to another - your JS may just be rendered useless.

In your case - I would be very vary to do JS manipulation, but I wouldn't base it on some higher principal.

Upvotes: 0

Sahil Muthoo
Sahil Muthoo

Reputation: 12519

  • jQuery is fundamentally a DOM/HTML manipulation library. Most of time when you're using jQuery, you're manipulating the DOM.
  • Ideally, such manipulation should only be used to progressively enhance the user experience. Wherever possible, the UX should gracefully degrade in case they cannot or choose not to run your Javascript.

I think you must ask yourself,

  1. Am I using jQuery/Javascript as the primary means to deliver my site's content?
  2. Is my site at least at the minimal level of usability with Javascript turned off?

If the answer to the first question is yes while to the second is no, I would go back to the drawing board.

Upvotes: 1

6502
6502

Reputation: 114481

I'm not sure I agree that using Javascript to modify a page is a bad idea. Javascript evolved in what it is now exactly to do that (including a standardized DOM).

Sure there are things that make no sense to do in Javascript like full validation (it may make sense to have sort of a pre-validation logic to give a better user experience but the server side must always do all the checks) but "manipulate HTML code" is not bad per se.

Clearly it dependes on what are the specific edits that you're in need to do. If for example is adjusting CSS then I agree that doing this with Javascript because the CMS doesn't allow it smells very bad as a solution (for example it will break if they touch the page generation in next update of the CMS).

Upvotes: 1

endyourif
endyourif

Reputation: 2202

I would definitely agree that it's not the best idea.

Typically search engines will not execute the Javascript and will read the pre-altered code.

Upvotes: 4

Related Questions