I am passing the ID of an element. At one point it no longer works. I think it needs to be forced to be seen as a string?
Hello all.
I have the following code that works if I hardcode the variable as I do here:
- function rw_getPositionOfPortfolioTarget(DivTargetPassed){
-
- // IF I HARDCODE THIS VAR HERE IT WORKS FINE
- var DivTargetPassed = "container_interactive";
-
- var portfolioTarget = $("div[id*="+DivTargetPassed+"]");
- var portfolioTargetPosition = portfolioTarget.position();
- var portfolioTargetleftPosition = portfolioTargetPosition.left;
- var portfolioTargettopPosition = portfolioTargetPosition.top;
-
- alert("left: " + portfolioTargetleftPosition + " top: " + portfolioTargettopPosition);
- };
Now if I pass the variable by getting the value from an attribute ID, it does not work. Please see the code that does this here
- function rw_PortfolioLinkControl(){
-
- $(".clickie").click(function(){
- var clickedPortfolio_Id = $(this).attr("id");
- rw_getPositionOfPortfolioTarget(clickedPortfolio_Id);
- });
-
- }
-
-
- function rw_getPositionOfPortfolioTarget(DivTargetPassed){
- //THE FOLLOWING ALERT READS THE ID CORRECTLY
- alert(DivTargetPassed);
-
- var portfolioTarget = $("div[id*="+DivTargetPassed+"]");
- var portfolioTargetPosition = portfolioTarget.position();
- var portfolioTargetleftPosition = portfolioTargetPosition.left;
- var portfolioTargettopPosition = portfolioTargetPosition.top;
-
- alert("left: " + portfolioTargetleftPosition + " top: " + portfolioTargettopPosition);
- //return false;
- };
In Line 12 you can see in my comment that I my alert does read the correct ID name. It does not however translate when I try to use the value to make the dynamic target as seen in Line 15.
This does work in the first code example when I actually pass the var value contained within quotes.
I am wondering if NOT giving it quotes in the second code block sample is the issue?
Do I need to ADD quotes somewhere in Line 15?
Do I need to define the value as a string since it may be coming through as something else??
Thanks for your help!
RW