March 3, 2013

PHP, quotes, and .html

Question by idigyourpast

I’m having a bit of a brain fart with this one line:

jQuery("#image-div").html("<img src='get.php?id_no='" + id + ">");

I’m trying to concatenate the <img> tag with a variable id but I can’t seem to get the quotes right. Stupid mistake, I know, but it’s just eluding me. Can I get a little help?

Answer by Matthew Blancarte

Looks like you were misplacing an apostrophe.

jQuery("#image-div").html("<img src='get.php?id_no=" + id + "'>");

Answer by Starx

You have an misplaced single quote in your code.

jQuery("#image-div").html("<img src='get.php?id_no='" + id + ">");
                                                // ^ This one here

It should be

jQuery("#image-div").html("<img src='get.php?id_no=" + id + "'>");
                                                          // ^ Should be here

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!