Why is .innerText not working in Firefox? [duplicate] - javascript

This question already has answers here:
'innerText' works in IE, but not in Firefox
(15 answers)
Closed 7 years ago.
Here is my code
It's working perfect in all browsers but not in Firefox.
I tried many thing but didn't work at all.
Please can some one help me on this issue.
Am I doing something wrong.?
Is there any other way.?
I'M USING .innerText because values are coming from
<span class="jr-rating-wrapper-jr_stars-new-0">
4.5
</span>
There is no error on console.
<script type="text/javascript">
jQuery('#submitButton').click(function(){
var PostStartone = document.getElementById('jr-rating-wrapper-jr_stars-new-0').innerText;
var PostStarSec = document.getElementById('jr-rating-wrapper-jr_stars-new-1').innerText;
var PostStarThird = document.getElementById('jr-rating-wrapper-jr_stars-new-2').innerText;
var PostCapVal = document.getElementById('code').value;
var PostRBVal = "";
var selected = jQuery("div.jr_fieldDiv input[type='radio']:checked");
PostRBVal = selected.val();
jQuery.post("http://xyz/x/Update.php", {
GetStarOneValue : PostStartone ,
GetStarSecValue : PostStarSec ,
GetStarThirdValue : PostStarThird ,
GetCaptchValue : PostCapVal,
GetRadioBTNValue : PostRBVal});
});
</script>

innerText is the "old Internet Explorer" way of doing it.
Try textContent instead. Ideally you should use elem.textContent || elem.innerText, but if you're using jQuery you can just do jQuery("#the_id_here").text().

Related

Javascript Snippet not working in Safari 11 & 12

does anyone know the reason why the following javascript snippet works in both Chrome & Firefox but not in the Safari 11 & 12 versions?
The only thing it does is take the value in the url parameter code and insert it in the url's on the page that need I want it to be in.
Are there any restrictions concerning javascript in the new Safari versions?
I can't find any info online..
<script>
window.addEventListener("DOMContentLoaded", function() {
if (window.location.href.indexOf('?code') > -1) {
var uniqueCode = window.location.search.split(/\?|&/g).filter(function(str){
return str.toLowerCase().indexOf('code') > -1
})[0].replace('code=','');
var codeLinks = document.querySelectorAll('[href*="/validate/promocode/"');
for (var i = 0; i < codeLinks.length; i++) {
var currentHref = codeLinks[i].href;
var newHref = currentHref.replace(/\/validate\/promocode\/.*\/buy\//, "/validate/promocode/" + uniqueCode + "/buy/");
codeLinks[i].href = newHref;
}
}
}, false);
</script>
I have no Mac to test this , but is it possible that Javascript is default disabled on version 11 and 12 on Mac?
Solved
The problem lies in the following line :
var codeLinks = document.querySelectorAll('[href*="/validate/promocode/"');
should be
var codeLinks = document.querySelectorAll('[href*="/validate/promocode/"]');
A small syntax error the other 4 browsers don't complain about.
Conclusion : Safari is much stricter on Syntaxerrors.

Detect IE by jQuery [duplicate]

This question already has answers here:
Browser detection in JavaScript? [duplicate]
(25 answers)
Closed 7 years ago.
I want to modify css of an element with jQuery only if the user agent is IE9 or later. How can I do this? This is my code:
var lancetta = $(document).find('.seconds');
if(msie version is >= 9){
lancetta.css({'-ms-transform' : 'rotateZ(360deg)'});
}else{
lancetta.css({'-webkit-transform' : 'rotateZ(360deg)',
'-moz-transform' : 'rotateZ(360deg)',
'transform' : 'rotateZ(360deg)'});
}
You can try this:
var IE9 = document.all && !window.atob;
if (IE9)
{
//IE9+ only
}
else
{
//rest
}

Firefox & IE does not run innertext

I have a problem like this :
<div id='stickyid' style='display:block; color:red'>happi</div>
After write :
<script type="text/javascript">
var thevalue = document.getElementById("stickyid").innerText;
document.write(""+thevalue+"");
</script>
It runs ok on Chrome but not Firefox and IE. How can I fix it?
Try:
var thevalue = document.getElementById("stickyid").innerText || document.getElementById("stickyid").textContent;
demo: http://jsfiddle.net/E3ESv/
var thevalue = document.getElementById("stickyid").textContent;
Please visit 'innerText' works in IE, but not in Firefox for more help

Get option.remove work in firefox javascript only

I have an class remover that works just fine in IE och Chrome, wont get any errors but in firefox. it dosent work at all.
Just get an error thats thas remove is not a function.
I been trying different ways to make it work, but none of them removes the class.
function removeDice(){
document.getElementsByClassName("dice")[0].remove(0);
}
An nice function that lets me remove dice classes one by one...
works in chrome but not firefox.
Been reading different methods here in stackoverflow and tried this
document.getElementById("dice").className =
document.getElementById("dice").className.replace
( /(?:^|\s)MyClass(?!\S)/g , '' )
But no luck either.
Any tips ?
Thanks
Have a try with this
Fiddle
function removeClass(classToRemove){
var elems = document.getElementsByClassName(classToRemove);
if (!elems) return;
for (var i=elems.length-1;i>=0;i--) {
var elem=elems[i];
var classes=elem.className.split(" ");
classes.splice(classes.indexOf(classToRemove),1);
elem.className=classes.join(" ");
}
}
Use removeAttribute()
document.getElementById("dice")[0].removeAttribute("class");
UPDATED:
Do this way:-
function removeClassFromAllElements(){
var objClass = document.getElementsByClassName("YOUR-CLASS-NAME");
var tempLen = objClass.length;
for (i=0; i<tempLen; i++) {
objClass[0].removeAttribute("class");
}
}
removeClassFromAllElements();
Refer LIVE DEMO

jQuery Cleditor wysiwyg text editor: keyup() works in webkit browsers but not Firefox or IE

I'm trying to follow up on a previous Stackoverflow question about how to display content from a Cleditor textbox in an external HTML element such as a <p>. Here's the question and the fiddle which solves my problem in webkit browsers but not Firefox or IE:
Here's the code from the fiddle:
<textarea id="input" name="input"></textarea>
<p id="x"></p>
<script>
$("#input").cleditor();
$(".cleditorMain iframe").contents().find('body').bind('keyup',function(){
var v = $(this).text(); // or .html() if desired
$('#x').html(v);
});
</script>
I've read Get content of iframe from jquery that I need to use "window.top.... to access the main page and pass it that way because .contents() is not supported by all browsers" but i'm not sure how to use window.top for this purpose and am hoping someone might be able to shed some light on this topic.
The cleditor documentation states that it does have a "change" event which it claims to work with the 'keyup' event, but unfortunately in my testing it didn't work as expected with Firefox 7 (requires clicking out of the text-editor).
Jsfiddle: http://jsfiddle.net/qm4G6/27/
Code:
var cledit = $("#input").cleditor()[0];
cledit.change(function(){
var v = this.$area.context.value;
$('#x').html(v);
});
There is also another StackOverflow question which asked about the same thing, in which user Ling suggests modifying the plugin to add your own function:
Get content from jquery CLEditor
Edit:
Based on your comments with the above SO question result's not working, I've amended the code below.
This works in IE9 and IE9's "IE8" developer mode. http://jsfiddle.net/qm4G6/80/
$(document).ready(function(){
var cledit = $("#inputcledit").cleditor()[0];
$(cledit.$frame[0]).attr("id","cleditCool");
var cleditFrame;
if(!document.frames)
{
cleditFrame = $("#cleditCool")[0].contentWindow.document;
}
else
{
cleditFrame = document.frames["cleditCool"].document;
}
$( cleditFrame ).bind('keyup', function(){
var v = $(this).text();
$('#x').html(v);
});
});
Another Edit: To get the HTML, you have to find body within the iframe like $(this).find("body").html(). See the code below.
JSFiddle: http://jsfiddle.net/qm4G6/84/
var cledit = $("#inputcledit").cleditor()[0];
$(cledit.$frame[0]).attr("id","cleditCool");
var cleditFrame;
if(!document.frames)
{
cleditFrame = $("#cleditCool")[0].contentWindow.document;
}
else
{
cleditFrame = document.frames["cleditCool"].document;
}
$( cleditFrame ).bind('keyup', function(){
var v = $(this).find("body").html();
$('#x').html(v);
});
$("div.cleditorToolbar, .cleditorPopup div").bind("click",function(){
var v = $( cleditFrame ).find("body").html();
$('#x').html(v);
});
Since I answered the question that prompted you for this, I guess I'll answer this one too ;)
This works in Chrome and Firefox (I don't have access to IE):
$("#input").cleditor();
$( $(".cleditorMain iframe")[0].contentWindow.document ).bind('keyup', function(){
var v = $(this).text(); // or .html() if desired
$('#x').html(v);
});
Updated jsFiddle
UPDATE
This also works in Chrome and Firefox. Maybe IE too?
$("#input").cleditor();
$( $(".cleditorMain iframe")[0].contentDocument ).bind('keyup', function(){
var v = $(this).text(); // or .html() if desired
$('#x').html(v);
});
jsFiddle

Categories