ascallonisi
ascallonisi

Reputation: 941

JQuery accessing PHP generated content

I have

<?php 
   include('print.php') 
?> 

That echoes html code inside my document, and after I load it I can't access the divs by id with jQuery

$("#"+divId)

It doesn't work even from chrome's console. I can access them with plain javascript

 document.getElementById(divId)

If I hardcode the divs I can access them via jQuery. Can anyone explain me why php-generated code is not accessible via jQuery?

Upvotes: 0

Views: 61

Answers (2)

ascallonisi
ascallonisi

Reputation: 941

In the end it proved to be a stuipid distraction, The fact that the content was dynamically generated on the server side was totally incidental. One of the divs contained a dot instead of a dash in the id ('#1.0'), so jquery was interpreting it as '#[id].[class]'

Upvotes: 0

GGio
GGio

Reputation: 7653

You need to use $('#' + divId) inside your document load. It does not work from chrome's console because variable divId does not exist.

Try this:

$(function() {
   var divId = Whatever your Div ID is;
   var div = $('#' + divId);
});

Upvotes: 2

Related Questions