1

I've managed to modify the content of certain H1's since I don't want them to return the value from the global variable. I used the code;

<script type="text/javascript">
$(document).ready(function() {
$("H1").filter(function() {  return $(this).text() === "Oak"; }).replaceWith('<H1>Solid Oak Furniture</H1>');
$("H1:contains('Countryside Oak')").replaceWith('<H1>Countryside Oak Furniture</H1>');  
});    
</script>

My question is when I view source, it shows the 'old' code.

Ex. Instead of showing <H1>Solid Oak Furniture</H1> it still shows <H1>Oak</H1>

But if I use, inspect element it shows the new code, <H1>Solid Oak Furniture</H1>

So which is actually on the current code?

durron597
  • 31,968
  • 17
  • 99
  • 158
ice
  • 11
  • 1

1 Answers1

2

When you view a page's source, it is generally the raw text returned by the web server at page load. Any manipulations to the DOM that were performed on the client's side will not be reflected.

Most modern element inspectors do correctly reflect the updates and manipulations from JavaScript and so forth. Don't worry, the correct HTML content is as you expect (i.e. <H1>Solid Oak Furniture</H1>).

That having been said, since JavaScript (and thus jQuery) is executed on the client side, modifications to the DOM are not generally included in search engine results, since their spiders do not usually include JavaScript engines. If you need to modify the DOM for SEO purposes, use PHP or manually change the HTML and re-upload to the web server.

BenM
  • 52,573
  • 26
  • 113
  • 168
  • Some spiders (Google's, for instance) do indeed do some minimal JavaScript interpretation. I very much doubt they trigger jQuery's `ready` event, and thus don't run the OP's code, but they do run some minimal JavaScript. See [my answer to "Do Google's crawlers interpret Javascript?"](http://stackoverflow.com/a/4225374/157247) which links to [this interview with Matt Cutts](http://www.searchnewz.com/topstory/news/sn-2-20100315SEOInterviewwithMattCutts.html). – T.J. Crowder Dec 20 '13 at 15:59
  • Thanks @BenM, I had feeling that would be the case. Looks like I'll have to create custom HTML then since PHP doesn't seem to work in bigcommerce. – ice Dec 20 '13 at 16:04
  • You cannot run PHP on Bigcommerce. That said you can configure what is wrapped in an H1 tag via your various templates (ie category, product). Or you can put the H1 tag in the product description if so desired (though that puts it pretty far down the page). – developerscott Dec 23 '13 at 16:06