RedInjection Posted October 31, 2015 Share Posted October 31, 2015 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. 1 Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted October 31, 2015 Share Posted October 31, 2015 You should avoid mixing languages altogether. Use a sepate JavaScript file instead of stuffing inline code into your HTML markup. And put the HTML markup below your PHP code to avoid spaghetti code: <?php // your code goes here ?> <!-- Your markup goes here --> Quote Link to comment Share on other sites More sharing options...
RedInjection Posted October 31, 2015 Author Share Posted October 31, 2015 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 Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted October 31, 2015 Share Posted October 31, 2015 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. Quote Link to comment Share on other sites More sharing options...
0x00 Posted October 31, 2015 Share Posted October 31, 2015 Sometimes I need to store JS in strings and also use two types of quote marks (there is more!), what you need to do is escape those characters by putting a backspace before them, just like you do when you do a new line ( \n ) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.