Thursday, May 2, 2024
 Popular · Latest · Hot · Upcoming
2
rated 0 times [  3] [ 1]  / answers: 1 / hits: 16622  / 15 Years ago, sun, may 10, 2009, 12:00:00

In Ruby you can use string interpolation like so:



text = This is visit number #{numVisits} to this website


This bypasses the need for explicit concatenation.



I'm working with jQuery and have a bit like this:



$(document).ready(function(){
$(a.ajax).click(function(event){
$(#content).load(data.html this.getClass);
});
});


The behavior I want is click on <a class=ajax id=schedule></a> and the content div on the current page is replaced by the schedule div from data.html. If I manually write in



load(data.html #test); 


that works, but I want the script to load the DIV with the ID value of the anchor clicked. Any help would be swell!



Example Page: http://www.mariahandalex.info/stack/


More From » jquery

 Answers
74

You cannot embed javascript code inside a string, but you can concatenate a string to an object using '+' like so



$('#content').load('data.html #' + $(this).getClass());


About embedding code in a string, I don't think it has a name. Groovy calls those strings Gstrings, and ruby calls those 'Expression substitution in strings'. I'm not sure it has a standard name.


[#99563] Tuesday, May 5, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
taylert

Total Points: 627
Total Questions: 91
Total Answers: 108

Location: Mayotte
Member since Mon, Sep 12, 2022
2 Years ago
taylert questions
;