How to convert all() function to work crossbrowser [duplicate] - javascript

This question already has answers here:
Replacement of .all() function for Browsers other than IE
(2 answers)
Closed 8 years ago.
I have below code. I want to convert this as cross browser compatible. As all() is IE only function i need to convert this. Please help me.
for(j=1,oTblRows=tblSource.rows,tLen=oTblRows.length;j<tLen;j++){
o=oTblRows[j].all("center");
if(o && (o.innerText === selCenter.value)){
$(oTblRows[j]).show();
}
else{
$(oTblRows[j]).hide();
}
}

I believe this is what you want. We want to match all elements with the id of "center" within the current row.
o=jQuery("#center", oTblRows[j])

Related

if runs with low-number >= high-number? [duplicate]

This question already has answers here:
Why is string "11" less than string "3"? [duplicate]
(6 answers)
Closed 3 years ago.
I am making a mistake or something strange is going on but I am not seeing it.
localStorage value = 9
if (localStorage.getItem('TotalProducts') >= '10') {
alert('total products'+localStorage.getItem('TotalProducts'));
}
Why am I receiving the alert?
Alert content is total products9
Thanks everyone for helping.
For others read the comments below there is some really useful information in there.
if (+localStorage.getItem('TotalProducts') >= 10) {
alert('total products'+localStorage.getItem('TotalProducts'));
}
Convert your TotalProducts value of localStorage to a number and then compare it to 10.

Find and delete cookie with javascript [duplicate]

This question already has answers here:
How to delete a cookie?
(13 answers)
Closed 6 years ago.
How would like to with javascript find a cookie that starts with 'AzureAppProxyAccess' and delete that cookie? It always has a series of random numbers at the end of the name. It is in the same domain so I have access to it.
This is what I have tried with jquery but I would like just javascript.
for (cookie in $.cookie()) {
if(cookie.substring(0, 19) === "AzureAppProxyAccess") {
$.removeCookie(cookie);
}
};
You can use indexOf in strings.
cookie.indexOf('AzureAppProxyAccess') > 1 ? doSomething : somethingElse
Or, like it was said in one of the comments, use RegEx.

How to check if location.hash has `#access_token=` and if so, do something? [duplicate]

This question already has answers here:
How to check whether a string contains a substring in JavaScript?
(3 answers)
Closed 6 years ago.
Right now, I'm just doing the following for my Auth0 login -
if (location.hash) {
// do something
}
How can I make sure it will only do this when it includes #access_token= ?
Use indexOf like so.
if(location.hash.indexOf("#access_token=" > -1) {
// Do stuff
}
You can learn more on indexOf here.

Array.indexOf Not working [duplicate]

This question already has answers here:
Why Array.indexOf doesn't find identical looking objects
(8 answers)
Closed 7 years ago.
I have an angularJS/Typescript application where I am trying to check if an object is already in a current list of objects
if (this.selectedFormatData.indexOf(item) === -1) {
//doesn't exist so add
this.selectedFormatData.push(item);
} else {
this.selectedFormatData.splice(this.selectedFormatData.indexOf(item), 1);
}
I have used this code before and it worked but isn't in this instance. Console output suggests it should work?
Any ideas?
Update: yeah correct looks like a duplicate sorry. I had a previous bit of code where i thought it worked because it was returning 0 instead of -1. Not sure why it would return 0 though
As the comments state, indexOf() is not meant to compare objects. This has been answered before here: Why Array.indexOf doesn't find identical looking objects.

searching values in array javascript [duplicate]

This question already has answers here:
Determine whether an array contains a value [duplicate]
(18 answers)
Closed 9 years ago.
Is there a built-in function in javascript to do this or this is only the option to go? Please look at the code below:
var arr=[1,3,4,'+','-', or whatever]
function value_check(user_click){
var operators=['+','-','/','*','.']
for (var i=0;i<operators.length;i++){
if (arr[arr.length-1]==operators[i]){var value1='operator found';}
if (user_click==operators[i]){
var value2= value1;alert("consecutive operators"); break;
}
}
}
I think this code achieves what I intend to do but is there a simple and shorter way of doing this. In words, I want to achieve something like this:
if (arr[arr.length-1] && user_click BOTH ARE IN operators array)
alert("consecutive operators)
Yes, there are some options:
JavaScript indexOf()
jQuery.inArray()
arrayName.indexOf() is what you are looking for.

Categories

Resources