where node_b is a pointer to a DOM object: node_b = document.getElementById("a") The reason I passed a DOM object into a variable, was to avoid searches document.getElementById() each time. However, it will not work. I am confused I cannot figure out if it a a mistake of mine or just the way javascript works.
Could anyone explain why I cannot use variables as DOM objects in order to avoit each time a tree search document.getElementById("a")? Bellow is given the code with explanation when it works and when it fails.
i am having two global variables and i m setting their values on calling some function. After setting the values, i call a function in an object ...
if MyHint is an object and i am calling the function in it, but i am getting the values of global variables as undefined in the function of object MyHint. Is there any way to access the value of the global variables.
I'm making some jQuery UI elements, and once an element is created, I want to add some custom functions and variables - I don't want to clutter up other jQuery objects by putting the functions in all jQuery objects, and obviously, the variables need to be different between different objects. However, the issue is, when I re-acquire the item, I won't have access to the variable any more.
That was probably confusing. Another way of putting it: (function($){ var _MyUI_id=0; jQuery.fn.MyUICreate = function(opts){ this.each(function(){ var obj=$(this)
//... code to turn the object into a MyUI object omitted to be concise obj.MyUI_id = _MyUI_id; _MyUI_id++; }}
})(jQuery) //now, create one $('#some_div').MyUICreate({}); //The desired effect would be to give me the id in #14, instead I get 'undefined'. alert($('#some_div').MyUI_id);
My 'solution', is to create an object variable in jQuery.fn called 'Collections'. It's indexes are the names of the new types, and each contains an object, the keys of which are the IDs of the UI elements that are converted to the type, and the values the jQueries objects. This is not only hackish, but it has a LOT of potential bugs. The code for this would look like:
This is in the 'create' function, at the end. jQuery.fn.Collections.MyUI[obj.attr('id')]=obj;
This is outside of the create function, but within the (function($){...}) scope. //jQuery.fn.Collections is set to {} in another file. jQuery.fn.Collections.MyUI={}; jQuery.fn.GetMyUI(id){ return jQuery.fn.Collections.MyUI(id); } This will allow the first block of code to work as desired, but it inserts a whole new set of bugs. What are the common ways to achieve what I am trying to do?
I've got a variable that holds a jQuery object. I would like to filter out all of the visible elements in that jQuery object. The problem is once I'm using a variable and not the jQuery object itself I don't know the semantics for filtering it. I have something like this:
var Foo = $("#Bar"); FilterFunction(Foo); function FilterFunction(Foo) { var Test = $(Foo + ":visible"); } What is the correct syntax?
I was wondering how you would list multiple variables after a equal ==? Example.... if ( pathname == schoolinformation, chaplainchatter) $('#button_newspress_archive,#button_tech_college,#button_parent_portal,#button_transition_portal,#button_6th_form,#button_connect,#button_vacancies,#button_vle_login').css('display', 'none'); $('#school_information_sub').css('display', 'block'); if ( pathname != schoolinformation, chaplainchatter) $('#school_information_sub').css('display', 'none');
Or even list multiple URL's within the variables? Example .... var schoolinformation = '/st-paul-s-website/school-information/school-news/headteachers-headlines', '/st-paul-s-website/school-information/school-news/chaplain-chatter-headlines';
I'm writing a function to populate a SELECT based on the select value of another SELECT. I can't figure out why this isn't working. It has something to do with not having "'s in my $(). for example: If this function wasn't dynamic.
The code: $(countryElementIDHash).val(); could simply be $("#country option:selected").val(); How can I pass dynamically assigned names into a $() ?
I have 3 TextFields, called txtUSD, txtEUR, txtAUS. And a PopupList with the same values, minus the txt part, but I need to form the names of the TextFields to use based on the selection that the user made. So I've done this:
Code: function btConvert_Click(event){ var amount = document.getElementById("txtAmount").value; var rates = document.getElementById("lstConvertTo").value; var from = "txt" + document.getElementById("lstFrom").options[document.getElementById('lstFrom').selectedIndex].text; var to = "txt" + document.getElementById("lstConvertTo").options[document.getElementById("lstConvertTo").selectedIndex].text; var curr_from = document.getElementById(from).value; var curr_to = document.getElementById(to).value; if(curr_from > curr_to){ amount * rates; } else { amount / rates; } alert(result); }
But every time I try it I get this error: Code: mobile/main.js line 215: Result of expression 'document.getElementById(from)' [null] is not an object.
Is there a way in Javascript or Jquery to return an array of all objects underneath a certain point, ie. the mouse position. Basically, I have a series of images which link to various web pages but I have a large semi transparent image positioned over the top of the other images. I want to find the href of the background image that the mouse pointer clicks over.
I have some JavaScript which is splitting out the different variable elements from the URL.Now, how do I set the internal variables?Then I want to set the variable ScriptHeading to be Change and the variable ScriptType to be NewThread.I keep finding all sorts of lovely code showing how to split out the various sections in many different ways, but I can't find anything on how to actually set these variables.
I have a program written in Javascript and fully functioning which takes a user-selected directory name and then displays all the photos in that directory in a certain format.
I am now wanting to expand the program to allow users to optionally enter their own strings and the program will use all the photos from www.flickr.com which use that string as a tag.
I have a PHP interface to flickr (called PHPflickr) which collects all the relevant photo urls. I now need to get these images back into my Javascript so I can process them using the existing functions (rather than rewrite all my functions in PHP code and have two sets of functions in the program). I found on another thread a means to do this for a date variable:
but being completely new to PHP I'm not sure what "addslashes" might be or what formatting will be necessary if I am starting with an array of urls. Code:
I am trying to figure out how to use objects properties in my code so when the page loads All my properties are in object where I can use elsewhere in my page. Code:
I'm trying to use the following code to load xml files:
ImportXML = function (ts) { this.file = ts; if (document.implementation && document.implementation.createDocument) { this.doc = document.implementation.createDocument("", "", null); this.doc.obj = this; this.doc.onload = this.callBack; this.doc.load(this.file); } else if (window.ActiveXObject) { this.doc = new ActiveXObject("Microsoft.XMLDOM"); this.doc.onreadystatechange = this.ready; this.doc.obj = this; this.doc.load(this.file); } else { alert("Error"); } } ImportXML.prototype.ready = function () { if (myDoc[counter].readyState == 4) this.obj.callBack(); } ImportXML.prototype.callBack = function () { alert('loaded'); }
var xmlDoc = new ImportXML("bar.xml");
The problem I'm having is with the second line that reads this.doc.obj = this;
IE tells me that object doesn't support this property or method. How is it possible to get a reference to the object (xmlDoc) in the prototypes 'ready' and 'callBack" with IE?
If you have a javascript interpreter running in an environment unknown to you (as in what objects it exposes to the language) is it possible to loop through all objects in some way?
This is a non-browser environment, specifically the scripting engine for doing xslt extensions in msxml.
"When we combine FUNCTIONS with OBJECTS we get METHODS". Then he creates an empty ARRAY:
var a = [];
then he uses the "push() method" to add elements to the array.
a.push(1,2,3);
uh, methods are for *objects* right? Yet he is using them on an ARRAY.how an array can magically becomes an object that is manipulated by a "method"?I mean, the array is still an array, no? It never actually becomes an object, right? Yet we still use a *method* to manipulate it. See my conceptual quandry?
I've often write javascripts that use this rather common code to get all tags in an XHTML document:
var alltags = document.getElementsByTagName('*') ... and then use a for loop to access the elements as an array, for example: for (i=0;i<alltags.length;i++) { elementClass=alltags.className [i]Do stuff }
This has always seemed to work in the past, but I recently learned that the getElementsByTagName method returns a DOM NodeList, not an array. I'm currenly working on a project that needs to access the children of an element conditionally upon its class.
I have three questions. First: How do I declare a global variable to be a DOM NodeList object? It wouldn't be assigned until called from a function, so something akin to var elementList = document.getElementsByTagName() in my global declarations is out of the question. Is there something like var elementList = new NodeList() in javascript? (I know that I can assign it in a function without the var and it will be global, but other people may have to work with this code, and I'd like to have it clearly declared at the head of the program.)
Second question: Assuming alltags is a NodeList returned from a getElementsByTagName call, which of these is proper? This:
childElements = alltags[i].getChildNodes() ... or this: childElements = alltags.item(i).getChildNodes() And finally, which of the above techniques has better browser support?
I recently had a problem where I needed to build up an array of strings, that would be join()ed into a string when the array building was complete. however, each value could only be in the array once.
This was a problem for a few reasons. Once a value has gone into an array the only way to check for it that works cross-platform is to scan the array looking for the value. FireFox has the every() and some() functions but they don't work in anything else.
Using an object to simulate an assocaiative array would allow me to avoid this problem by storing key/values with the keys having the same value as the value I was storing. I could then use the (a in b) construct to check that I had not already added a value.
However, array type methods won't work with objects, so I had no access to size () or join () meaning I'd have to manually build the string by iterating over the object.
My solution was to use an array object, but to store the provided data i nboth the array proper and as a property of the array object.
var myArray = new Array;
function addVal (val) { if (!(val in myArray)) { myArray [val] = 1; myArray.push (val); } }
This approach does use up more memory but it does give me the advantages of both arrays and objects for little extra work. (if you don't have FireBug then replace console.log with alert)
That arrTD will have an array of "HTML DOM TableData Objects".
Now what is the best way to access each object and see what it contains. I would like see which properties each object has and what their values are. I also guess there could be some other objects within the TD object and maybe even some events and methods.
Now I have been reading an on-line reference about DOM, but I think it is a little dated.
http://www.w3schools.com/htmldom/default.asp
For example I know that a <TD> can contain class="something" but I could not find a property called class, but it did list others like id, align etc.
I would like to learn how to access and view the contents of a DOM object.
I would like to have page which uses a few xhr objects and automatically (after 30 seconds) starts the same few requests again It works for me well in IE7, IE8, but not IE6 (where is in browsing history chosen option "automatically" ). It works there only for first time and I can't set it for circular reloading. It looks like page is reloaded, but xhr objects are not doing their job ...only - as I wrote - for first time after page load.
Does anyone know of any generic code to clone an object (which only contains properties), which copies by value, not just reference?
It seems as though there should be some sort of prefab recursive function that could work for any old object, so I didn't want to re-invent the wheel Code:
I am dabbling with objects and have successfully created an object with various properties, one of which is an Array, and all is fine. the Question I have is can I make an Array of objects? I have the following object:
dataSeries.Type = value dataSeries.Name = value dataSeries.dataPoints[n] = Array of values dataSeries.color = value
What I would like to do is have an Array of multiple objects supposedly like:
dataSeries[0].Type = value dataSeries[1].Name = value dataSeries[2].dataPoints[n] = Array of values dataSeries[3].color = value
I've tried breaking out an application I'm working on into smaller objects. I have always had the objects built out, but they were nothing more than local variables. So I tried to create a few methods and include them in one of the objects (the Map object). Code:
I have a data structure that is composed of an array of JavaScript objects (my own created classes) that I need to pass as a parameter to an URL:
I would like to know if there is a way to serialize this array, send it as a string, then deserialize it on the other side, resulting with the data structure again I am trying to avoid doing the serialization myself.
Each entry in the array holds an object of type Person: