really simple question, just having a hard time actually making it work. I have a snipet of code that's javascript that I'm trying to write in jquery and can't quite get it.
effects_of_yoga_2010_INFO.style.setProperty('-webkit-transform',
'rotateZ('+effects_of_yoga_2010_DEG+'deg)');
and I had tried it as
$("#effects_of_yoga_2010_INFO").css("-webkit-transform",
"rotateZ('+effects_of_yoga_2010_DEG+'deg)");
but the jquery snippet doesn't work, I'd really appreciate any help I can get on this, I'm sure it'll be breeze for someone.
It should be:
$("#effects_of_yoga_2010_INFO").css("-webkit-transform",
"rotateZ("+effects_of_yoga_2010_DEG+"deg)");
you were mixing single quotes with double quotes.
Assuming effects_of_yoga_2010_DEG is another id of an element with a value, try:
$("#effects_of_yoga_2010_INFO").css("-webkit-transform",
"rotateZ('" + $("#effects_of_yoga_2010_DEG").val() +"'deg)");
$("#effects_of_yoga_2010_INFO").css("-webkit-transform", "rotateZ('+effects_of_yoga_2010_DEG+'deg)");
That doesn't look right. Unless this was a copy-paste error you should split the variable values from the rest of the strings the same way as the JavaScript version had done.
$("#effects_of_yoga_2010_INFO").css("-webkit-transform", "rotateZ(" + effects_of_yoga_2010_DEG + "deg)");
Of course, this is based on not knowing what effects_of_yoga_2010_DEG is. I'm assuming it simply contains the value you are looking for and can be used the same as the JavaScript version had done.
Related
So many related questions out there, but none satisfyingly answered using javascript (no jQuery).
I wish to add quotes around a variable in a string I'm building. My string itself should contain single quotes within it like so:
'{'a'}'
I can get:
'{a}'
When I try to add single quotes around the key a I get:
'{\'a\'}'
I've used both of the following syntax with the same result.
Any suggestions??
concat('\'','a','\'')
'\''+'a'+'\''
See line 39 of this code: https://repl.it/#mike_butak/LiveForHisPleasureHeReallyIsThere
Thanks!
Like this?
console.log("'{'a'}'")
To expand on this, when you are building the string, just use " around the string, and ' within the string.
Having a hard time replicating your issue! See:
var temp = '\'{\'a\'}\'';
console.log('s' + temp + 's');
I'd definitely recommend demonstrating the issue you are asking about in a console print or in a readily available editor online before posting a question!
As per your comment, updating to make it part of a variable assignment. Still unclear what the issue is!
I'm having an issue trying to set an input field's value when using HTML entities in that they are coming out literally as " rather than ".
Here is the code I am using:
document.getElementById('inputSurname').setAttribute('value', 'test"""');
in which the output is test""" though I want the output to be test""".
It doesn't look like a double-encoding issue since in the source code I am seeing it the same way I have set it here.
I know I could decode the value from its HTML entity format though this is something I want to avoid if possible for security.
Any help would be much appreciated :)
Try this:
document.getElementById('inputSurname').value = 'test"""';
Or if you want to keep ":
function myFunction() {
document.getElementById('myText').value = replaceQuot('test"""');
}
function replaceQuot(string){
return string.replace('"', '""');
}
Or you can use escape characters.
document.getElementById("inputSurname").setAttribute("value", "test\"\"\"\"");
Well you could just write the new value as 'test"""'.
For other characters however, I'm going to refer you to this answer: HTML Entity Decode
i've searched on the site but i could find nothing that could help me.
I have a javascript code inside html inside php, i would like to know how i can put a string inside the javascript code with "breaking" the href with double quotes. Here is the code i have:
return '<li class="slide_li" onmouseover="gmarkers['+marker_num+'].setIcon(getMarkerImage("grey", price, cur));" onmouseout="gmarkers['+marker_num+'].setIcon(gicons.blue)">'+details+'</li>';
The "grey" value breaks the href, i tried different ways like:
'grey', \'grey\', \"grey\" ecc.. but none of this worked for me. Any help is really appreciated. Thanx!
To avoid such pain in the future, I am suggesting you my way of doing things in such scenarios.
Since you are already using jQuery library, why not to use its way of handling events:
$('li.slide_li').on({
mouseover: function(e){
},
mouseoutleave:function(e){
});
instead of using inline javascript. This will make you away from dealing with quotes. Additionnaly, by seperating the concerns this way, you make your php return only markup.
About additional variables (like the variable containing 'grey'), I suggest you use data attributes, something like:
return '<li class="slide_li" data-color='grey'></li>
in javascript:
var color= $('li.slide_li').data(color);
// use color variable in code inside mouseover and mouseout
I am not telling here that the other answers are not adressing your current problem, I am only sharing a way I was told in the past it is a better way.
You need to wrap your javascript variable with additional single quote and then you need to used backslash like below:
return '<li class="slide_li" onmouseover="gmarkers[\''+marker_num+'\'].setIcon(getMarkerImage("grey", price, cur));" onmouseout="gmarkers[\''+marker_num+'\'].setIcon(gicons.blue)">'+details+'</li>';
I tried with this "grey"
and it works!
Thank you everybody!
Try setting the variable outside of the javascript first:
var variable="grey"
return '<li class="slide_li" onmouseover="gmarkers['+marker_num+']
.setIcon(getMarkerImage(variable, price, cur));" onmouseout="gmarkers['+marker_num+']
.setIcon(gicons.blue)">'+details+'</li>'
;
This seems so simple and I honestly can't see why this isn't working. Looked at other answers on here and mine still isn't working.
var randomArray = new Array();
randomArray[0] = 859;
alert(randomArray[0]);
How come nothing happens? It's probably an easy answer but I can't work it out.
Also, I'm trying to work out how to put a random number in the array so rather than putting 859 in index 0 lets say I want to put a random number between 1 and 20 in, so far I've got this but thats not working either
randomArray[1]=Math.floor(Math.random()*3);
EDIT: the .toString on alert seemed to fix it, thanks guys, knew it would be something small!
Is your javascript being referenced properly in a script tag with the correct type set?
<script type="text/javascript" ...> </script>
If not, it's fully possible your browser is simply ignoring it.
This is a wild guess, because your question doesn't contain enough information to know for sure, but make sure that your code is in a <script> block that looks like this:
<script>
// your code
</script>
Get rid of any "type" or "language" attribute on the tag; they're not needed and they're a source of error. If the "type" value is mispelled, then the browser will completely ignore the code.
Try calling .ToString() on your array property.
alert(randomArray[0].toString());
I am trying to get the innerHTML of a hidden span. The JavaScript is from an iframe HTML page, and the hidden span resides in the parent page. A different function works when accessing contents of a list from the parent, but I can't seem to get at my span...
WORKS
document.getElementById(parent.genL[i]);
DOESNT WORK
document.getElementById(parent."span"+i).innerHTML;
- SyntaxError: missing name after . operator
The above line of code resides in a for loop and as it iterates through i it will grab data from each separate span. the hidden spans start at ID "span1" through upwards of 10-40k different hidden spans.
Anyways, I have a feeling that it has to do something with trying to concatenate the string int i. I assume i is an int anyways. Any thoughts? Thanks so much everyone!
Edit - Words, and added the innerHTML portion to the doesn't work line of code. Not sure if that will be making a difference or not...
Edit2 - Great answers everyone, learned some good syntactical tricks :) I simply moved the parent. portion to the front of the code as reccomend by the comment of mplungjan and the answer from Jacob T. Nielson. For some reason I still got the error using the brackets as suggested, but I will definitely tuck the brackets into my memory for future similar situations!
parent.document.getElementById("span"+i).innerHTML;
:)
Try changing it to an indexer.
document.getElementById(parent["span"+i]);
If the parent in the brackets is an object and you're trying to access something like parent.span1 then you need to use bracket notation instead of the dot.
document.getElementById(parent["span"+i]); should work fine.
I think what you are trying to do is get the i-th span element on the parent page. Correct?
You can do it like this
var s = parent.document.getElementsByTagName('span')[i];
s.innerHTML // <-- access innerHTML