0

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?

4
  • 3
    show us your code. HTML, PHP and Javascript code. Commented Aug 21, 2014 at 16:47
  • inspect element and post the html here Commented Aug 21, 2014 at 16:49
  • 1
    Are you including Jquery Library Commented Aug 21, 2014 at 16:50
  • php is rendered on the server, before the client even loads. so there is an error with your code, it can't be related to php. Commented Aug 21, 2014 at 16:51

2 Answers 2

2

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);
});
Sign up to request clarification or add additional context in comments.

Comments

0

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]'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.