jQuery ready state for DOM

Today I was trying out jQuery and trying to addClass to a p tag. I was doing it at the top of the page i.e.

{code type=’codetype’}

<head>

<script src=”jqeury.js”>

$(“p”).addClass(“selected”)

</script>

</head>

<body>

<p>Hello</p>

</body>

{/code}

This will not work because the p tag is below the jQuery code. jQuery looks for the p tag above the lines it was written in.

To overcome this problem, you can either write the above script withing  $(docment).ready(function() {}) function or write the jQuery script after the p tag was written.

i.e.

{code type=’codetype’}

<head>

<script src=”jqeury.js”>

$(document).ready(function(){

$(“p”).addClass(“selected”);

};

</script>

</head>

<body>

<p>Hello</p>

</body>

{/code}

or

{code type=’codetype’}

<head></head>

<body>

<p>Hello</p>

<script src=”jqeury.js”>

$(“p”).addClass(“selected”)

</script>

</body>

{/code}

When using the ready() function the jQuery statement is executed after the DOM has loaded completely thus allowing the p tag below the code to be found.

PHP Short Tags

My project which was written using Codeigniter framework used php short tags and I did some research and setup my localhost to work with it.

PHP short tags refer to the alternative way of writing php tags in a web script. i.e. <?= [function/variable]  ?>instead of <? php  echo [function/variable] ?>


Today while working on one my projects, I found that I needed to turn on PHP SHORT TAGS in the php.ini to make it work properly. The project uses codeigniter framework and the previous developer used php short tags in his code which was not setup on my localhost. So I enabled it by editing the php.ini file and setting the short_open_tag variable to on and then restarted the apache server and it worked.