• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Inner HTML not running JavaScript

 
Luke Powl
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So i have this script running (which works perfect) The REL attribute is linked to a Jquery plugin called Shadow box that is the only thing I need to get working. Currently it seems that Javascript is not even running within the innerhtml.




Then it displays the page on the side of my other page perfectly. Now the problem I am having is i need to run Javascript from that innerhtml ,

My Innerhtml is

Any Ideas why my page is not loading JavaScript?

I appreciate any help in advance!
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64958
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just shoving script into innerHTML isn't going to make it run.

You say you are using jQuery, so why aren't you using it to do your Ajax? jQuery will cause the script to execute when loaded with the .load() method.
 
Luke Powl
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The jquery loads when you click on the link. Not when the page is loaded . Not sure if that helps you undestand what im doing ?
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
putting JavaScript on the page with innerHTML is not going to run. The browser does not evaluate it.

Libraries like jQuery pull out the scripts and eval() it.

Eric
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64958
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure if that helps you undestand what im doing ?
Then let me summate: you are loading some HTML and script, generated by PHP, from the server via Ajax. The script in this loaded block is not executing when you insert the block into the DOM using innerHTML.

Is that correct?

If so, my reply stands.

[As does Eric's which says the exact same thing I said.]
 
Luke Powl
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you! I understand now, And i am unsure how to change from ajax to jquery simply. It sounds almost a hassle but I guess i have the itme ill switch over.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64958
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Loading an element with jQuery:

Doesn't seem like rocket science to me!
 
Luke Powl
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
FYI,
This worked inside the innerHTML


<img style="cursor:pointer" src="<?php echo $this->url('images/layout3/icons/icon-bandwidth.gif')?>" onclick="Shadowbox.open({ content:'<?php echo $this->url("networktools/".$c->ip."/bandwidthgraph");?>', width:'750',height:'580', player:'iframe'}); return false;" >
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64958
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, there's no script block in that.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic