Welcome Guest, Not a member yet? Register   Sign In
best way to handle several body onload
#1

[eluser]zenon[/eluser]
Hi, I'm using jquery routine to init all elements where body document is laoded.

Code:
$(document).ready(function(){

});

How could I handle this routine for each page?

One solution may be to build a first common header part and another specified on each controller, but another solution I heard could be to inject a javascript source still from controller.
Have you ever hear about this?
However, which approach do you use?

Thank you Smile
#2

[eluser]R_Nelson[/eluser]
can you give an example of what your trying to do your question seems a bit vague to me
#3

[eluser]Namaless[/eluser]
Code:
jQuery(document).ready(function() {
    <?php if ( $page == 'test' ) : ?>
        jQuery('#test').show();
    <?php else : ?>
        jQuery('#test').hide();
    <?php endif; ?>
});

This is only simple example to use with
Code:
$this->load->view( 'jquery_script' );
#4

[eluser]joakley77[/eluser]
Not sure exactly what you're trying to do but why not use one .js file and do whatever you need to do if the element is visible?

Code:
$(document).ready(function() {
  if ($('#element').is(':visible') {
    // do something
  } else if ($('#another_element').is(':visible')) {
    // do something with this element
  }
});
#5

[eluser]bubbafoley[/eluser]
you can have multiple document ready functions

http://www.learningjquery.com/2006/09/mu...ment-ready
#6

[eluser]zenon[/eluser]
[quote author="Namaless" date="1299719143"]
Code:
This is only simple example to use with [CODE]$this->load->view( 'jquery_script' );
[/quote]

What stands for jquery_script?

Is it a .js ?

If so, I would keep the script tag inside head element, as w3c suggests.

A possible solution would be

Code:
$this->load->view( 'header_first_part' ); // open <head> element
$this->load->view( 'jquery_script' );
$this->load->view( 'header_last_part' ); // close <head> element
#7

[eluser]zenon[/eluser]
[quote author="bubbafoley" date="1299724923"]you can have multiple document ready functions

http://www.learningjquery.com/2006/09/mu...ment-ready[/quote]

I can't figure out how use it.

Can you make a more accurate example please?

thank you! Smile




Theme © iAndrew 2016 - Forum software by © MyBB