Jump to content

Convert Javascript so PHP ECHO can read it


RedInjection

Recommended Posts

Hello all!

 

I am aware of how to use \" when escaping HTML tags but I want to know how people do it with javascript as I have a very complex JS I have wrote which I need to integrate with PHP

 

As an example

$(".hide1").hide(); $(".show1").show();
$('.show1').click(function(){$(".hide1").slideToggle();});

I know that

 

ECHO '$(".hide1").hide(); $(".show1").show();';

ECHO '$('.show1').click(function(){$(".hide1").slideToggle();});';
 
Isn't going to do it, what characters in that above code need to be escaped, is it possible I can convert the $ sign using HTML character codes? $ so it can read it easier and allow me to produce the output I want.
 
Thanks.
  • Like 1
Link to comment
Share on other sites

I am creating a jquery that hides/displays information when a hyperlink is clicked, so I have a while loop to count records but jquery needs me to define a variable for each hyperlink so I am going to increment it.

 

I need to integrate jquery so I need to be able to insert it because of this

Link to comment
Share on other sites

jQuery certainly does not require you to define a new variable for each element. It supports intelligent selectors to get child elements, sibling elements etc. And if that doesn't help, you can always store information within an HTML element using data attributes.

 

If you describe the problem, I'm sure somebody will find a more intelligent approach than tons of numbered variables.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.