Difference Between Class And Name Properties In HTML, As Applied To JavaScript

Dec 17, 2001

how the class attribute works in CSS: I can specify that every attribute with class="foo" be italicized with: .foo {font-style: italic;}

What if I want to do the same sort of thing in Javascript? Is there something built-in like document.GetElementsbyClass("foo").style = "italic" (I'm just making this code up of the top of my head, I don't know how javascript works.)

It seems to me that with JavaScript you're supposed to use the name="" attribute instead of class="". Why the diference?

I looked at webmonkey that had an article about this, but their writing style is simply confusing and I can't make heads or tails of their articles.

View 1 Replies


ADVERTISEMENT

Object Properties With Array Syntax - Add Extra Properties To Html Elements

Nov 13, 2009

how to add extra properties to html elements as I was storing data in html attributes. After looking at some others code including Raphael and this addEvent code. [URL] They seem to treat objects just like an array. obj[property] = value; This would have been extremely helpful to know previously as I have needed to be able to include variables in property names - but have resorted to making the whole thing a string and calling exec() on it.

View 2 Replies View Related

JQuery :: On Click Add Class Not Staying Applied

Mar 29, 2010

I'm trying to add am active class to my menu when the link is clicked using the following [code]...

The active class gets applied but them disappears straight away. Is there something I've missed.

View 3 Replies View Related

JQuery :: Getting A Selector Working - Expect The Class Of 'testclass' To Be Applied To The Button After The Link Is Clicked

Feb 7, 2010

I'm having trouble getting a selector working. Probably best just to give you some example code:

HTML
<input type='button' class='test' value='Button Name'>
<div>
<a href='' class='buttonLink' />Click me</a>
</div>
Jquery
$(.buttonLink).click(function() { $(this).closest(':button.test').addClass('testclass'); });

Form that code I would expect the class of 'testclass' to be applied to the button after the link is clicked, but It doesn't seem to work. This is a somewhat contrived example. In my real application I have a form with several collapsable/expandable sections. If the fields in those form sections have values when the page loads, the section needs to be expanded, and the expand/collapse button needs to have a class of 'expaned' applied to it, if not it needs to be hidden. I can check the form fields and show the div if needed without any problem, but I can't seem to figure out how to work out the selector so I can add the class to the button.

View 7 Replies View Related

JQuery :: A New Loaded Html Elements Can't Be Applied Function?

Apr 4, 2011

I already make this line of code

$('#bank').click(function(event){
// request form
$('#middle').load('form/bank.html');
$('#butang').click(function(){

[Code].....

Which means, once after a link namely as "bank" is clicked,then it will extract the bank.html contentinto the middle div. And I already put a button ID named as "butang" over that bank.html. But why after the content is nicely rendered, I can't obtain the alert?

Hmmm... even when I clicking, clicking, and clicking many times at the button named as "butang", can not also give me an alert. How could I apply a jquery into a new html rendered as it firstly it's not there?

View 3 Replies View Related

JQuery :: Using AJAX To Inject Html But What To Inject To Get Css Applied To Requested Html?

Nov 8, 2010

I'm using jQuery AJAX to request html pages so no refreshes will be needed when someone clicks an menu item. But the things is, I'm currently requesting HTML pages with no doctype, head and body tags.. just only the content (with just h1 tags and tags like that). The problem is that when I inject that into an div on my main page the css doesn't get applied to the injected content. It does set the text color and makes H1 an heading but it doesn't apply specific things like h1:first-letter. So I'm assuming it only applies general css properties like the text format I applied to the body of the main page. So the question is how can I make the css apply to the AJAX requested and injected content? Should I include an css file to the file I'm requesting? Should I use some jQuery function to apply it after the injection? Or .. ?

View 1 Replies View Related

Changing Class Properties

Jul 20, 2005

I have a number of elements of "some-class".

I'd like to change the styles of some-class:

from

..some-class{color: red; display: block}

to

..some-class{color: red; display: none}

How do I do that?

View 6 Replies View Related

Change The Properties Of A Css Class?

Apr 11, 2010

I'm trying to make a webpage where you can change the colour of various elements within the page, which has numerous div classes in the css and numerous divs all with different names. What I'm trying to work out and can't find anywhere is can you change the properties of a css class using javascript, and if so, how?

View 2 Replies View Related

Spidermonkey Embedding: How Can I Set Class Properties?

Jul 23, 2005

I am embedding Spidermonkey in a C app. and I'm having trouble setting
class (not instance) property values. For example, I am setting up
the class as follows:

static JSBool constructor(JSContext *cx, JSObject *obj, uintN argc, jsval
*argv, jsval *rval)
{
printf("constructor argc = %d
", argc);
*rval = OBJECT_TO_JSVAL(obj);
return JS_TRUE;
}

main()
{
....
static JSClass my_class = {
"MyClass", JSCLASS_HAS_PRIVATE,
JS_PropertyStub,JS_PropertyStub,JS_PropertyStub,JS _PropertyStub,
JS_EnumerateStub,JS_ResolveStub,JS_ConvertStub,JS_ FinalizeStub
};
static JSPropertySpec class_props[] = {
{"Prop1", 0, JSPROP_ENUMERATE},
{0}
};
JSObject *proto;

proto = JS_InitClass(cx, JS_GetGlobalObject(cx), 0, &my_class,
constructor, 1, NULL, NULL, class_props, NULL);

The above code correctly (verified through a JavaScript program). creates a new class with the Prop1 class property.

The following code correctly adds an _instance_ property:

jsval val = INT_TO_JSVAL(42);
JS_SetProperty(cx, proto, "MyProp2", &val);

After three days I still can't figure out how to set the value of the class
property, or, for that matter, create a new class property with a particular value. I am looking to do something like this:

jsval val = INT_TO_JSVAL(88);
JS_SetProperty(cx, ???, "Prop1", &val);

View 3 Replies View Related

Change The Display Properties Of A Class

Jul 28, 2006

can u change the display properties of elements in a certain class?

View 1 Replies View Related

Change CSS Properties Of Each New Instance Of Class?

Dec 14, 2009

I need to change the background-image (or possibly background-position) property of each new instance of a div with a particular class. I will have a set of images to choose from, or could create a sprite with all of the images.

Example:

Code:

<div class="desc">content</div> **needs background-image: url(pic1.jpg)
<div class="desc">content</div> **needs background-image: url(pic2.jpg)
...
etc.

The page code is dynamically generated from our CMS, so can't change the HTML.

View 3 Replies View Related

Text/javascript, Application/x-javascript, Difference?

Feb 19, 2007

two possibilities or the attribute type of script:

text/javascript (the one i usually use) application/x-javascript

what are the differencies between both?

depends on the html content?

for example html 4.0.1 versus xhtml 1.1?

View 12 Replies View Related

JQuery :: Brain Fade Add Css Properties To A Class?

May 13, 2010

ie. the equivalent of typing them in a style sheet, but doing it dynamically?

View 6 Replies View Related

JQuery :: Get Class Properties In Event Handler (in OOP)

Feb 3, 2011

i'm looking for the best way to use global properties that defined at class level insid event handler functions.

for example :
function MyClass() {
this.v1 = "hello";
this.v2 = {name: 'joe', age:'30'};
this.link1 = $("<a/>", {id: "link1"});

[Code].....

actually, in link1Handler 'this' returns to link1 not to main class. so how to get class properties or functions inside the private functions of the same class?

View 2 Replies View Related

Difference Between JS And HTML?

Sep 8, 2011

I inherited an html demo (used to show customers our product w/o being connected to a server). Was going through the Html files to update the dates and fields and it seems that on some html files, when I change a date <td>08/11/2008 </td> to <td>08/11/2011</td>, save and refesh, I start getting a bunch of JS errors when I try and log back into the demo. I'm not changing anything in the JS files, so I don't understand why the errors are occuring.

I have a bunch of html files to change, and now, no matter which file I change (the dates, sample names, etc), I lose functionality on that particular page.

View 3 Replies View Related

Javascript Function Has No Properties In Javascript Console

May 25, 2005

I'm getting errors in Firefox everytime I try to run this frame resize code, but it works fine in IE. I can't seem to figure out what the problem is with it.

The error is: Error: theFrame has no properties
Line: 8

The line that the javascript console is showing an error for is in italics.

code from page:

<html>
<head>
<script type="text/javascript">
var defaultCols="100px,*";
var hiddenCols="0px,*";
function ShowHideMenu(){
theFrame = document.getElementById("framed");
if(theFrame.cols == defaultCols) theFrame.cols=hiddenCols;
else theFrame.cols=defaultCols;
}
</script>
<frameset cols="100px,*" name="framed">
<frame src="lframe.htm" name="frameMenu">
<frame src="mframe.htm" name="content">
</frameset>
</head>
<body>
</body></html>

Come someone let me know what I'm doing wrong here?

View 2 Replies View Related

JavaScript Date Difference, Accounting For Leap Years

Jun 19, 2006

I'm really sorry to post this as I know it must have been asked
countless times before, but I can't find an answer anywhere.

Does anyone have a snippet of JavaScript code I could borrow which
calculated the difference in years and days between two dates, and
takes leap years into account?

I'm calculating the difference in the usual way, i.e....

var difference = dateTo.getTime() - dateFrom.getTime();

....and converting this millisecond value into days by using...

var daysDifference = (difference/1000/60/60/24);

But how do I then display the difference in days AND years? I've tried
the following:

var yearsDifference = Math.floor(daysDifference/365.25);
var daysLeft = Math.floor(daysDifference-(yearsDifference*365.25));

....but it gives me inaccuracies. For example, if I use my code to
calculate the difference between 05/01/1998 and 05/01/2000 it returns 1
year and 364 days!

View 4 Replies View Related

Difference In Calling Javascript In Href And Onclick Of Anchor Tag.

Jan 18, 2006

I am looking for a generic javascript function to identify the form with in which a element exists, thus developer can avoid coding like document.forms[index].submit() - where they are sure, they want the form with in which this element exists is to be submitted. This way when forms are introduced at top level the code can remain unchanged, else every form introduce above in the DOM will result in increasing the index by one.

The code is given below. While doing so i am stuck with 2 problems
P1: In the code, you can see i am giving a explicit 'break' in the code. If i don't do so the code seems to be looping. Obviously i am missing some basic.

P2: I am able to pass 'this' for anchor element by name="xy"
<a href="#" name="xy"

in its onclick function by which, in the javascript function i move up the DOM.

While i am unable to do that on the anchor element given below since this function is now on the href attribute.

<a name="xy1" href="javascript:doFormSubmit(this);">Q test</a>

Hence the script fails. Code:

View 10 Replies View Related

Subtract Values From Two Text Boxes And Then Show The Difference Into A Html Label

Jan 12, 2010

I neeed to subtract values from two text boxes and then show the difference into a html label.

Basically I need to enter times, like 10:00 and 12:00 and it calculate that the difference was 2 hours.

View 12 Replies View Related

Detect Pdf Properties Using Javascript

Jul 23, 2005

I would like to generate a page of links including some of the pdf properties (title, author, version, etc.) for a folder full of pdf's. Is this possible from Javascript?

View 4 Replies View Related

Javascript Window Properties ...

Nov 8, 2005

Is it possible to remove the site address from the title to a javascript window?

View 3 Replies View Related

JQuery :: Difference Between Class Selector And ID Selector?

Sep 8, 2011

Are there any difference between class selector and ID selector

View 2 Replies View Related

Converting HTML <a> Tag - Add The Class To It

Jun 21, 2010

<a href="www.mylink.com" class="myclass">click</a>

and I wanna change it to a javascript function that can be called via the SAME tag, but with this link:

[Code]...

this works to the point where it only opens the link, but now i can't figure out how to add the class to it. I tried adding it inside the body tag, but it doesn't work. So, I'm wondering if it's possible to set the class in the javascript.

View 4 Replies View Related

Dynamically Writing Html/javascript From A Javascript Function

Jul 23, 2005

I'm working on some code and am running into brick walls. I'm trying
to write out Javascript with Javascript and I've read the clj Meta FAQ
and didn't see the answer, read many similar posts (with no luck
though), and searched through the IRT.ORG Faqs
(www.irt.org/script/script.htm).

The Javascript is designed to open an popup window and then inside that
window call another script which will resize that window. There may be
another way around this but the reason I tried this approach initially
was that I wanted to call the onload handler in the popup window to
resize the image only after the image had completely loaded. I've had
some code in the primary Javascript file (showimage.js) before that
works if the image has been cached but on the first load, it doesn't
resize properly which tells me it is probably because it is trying to
resize the window based on the image size but it isn't completely known
at that point. So I removed that code and tried placing the resizing
code in the second Javascript file (resizewindow.js). BTW I've tried
other code to open a popup image and automatically size it ie Q1443 at
irt.org but that doesn't do exactly what we need.

Even if there is another way to do this with one file, I still want to
figure out why this isn't working in case I run into it in the future.

I thought what I would need to do to use document.writeln to write
Javascript would be to escape any special characters and to break
apart the script tag ie

document.writeln('</SCRIPT>');

would become

document.writeln('</SCR' + 'IPT>');

I have a HTML page and 2 Javascript files. All files are in the same
directory and have permissions set correctly.

Here are the 3 files (keep in mind wordwrap has jacked up the
formatting):

index.html
----------
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Test</title>
<SCRIPT type="text/javascript" LANGUAGE="JavaScript1.1"
SRC="showimage.js">
</SCRIPT>
</head>

<body>
Click the house<BR>
<A ONCLICK="newWindow1('house1.jpg','Nice House')"><IMG
SRC="house1thumb.jpg"></A>
</body>
</html>


showimage.js
------------
function newWindow1(pic,sitename)
{

picWindow=window.open('','','width=25,height=25,sc rollbars=1,resizable=1');
picWindow.document.writeln('<html> <head>');
picWindow.document.writeln('<SCR' + 'IPT type="text/javascript"
LANGUAGE="JavaScript1.1" SRC="resizewindow.js"></SCR' + 'IPT>');
picWindow.document.writeln('</head>');
picWindow.document.writeln('<body onload="resizewindow();">');
picWindow.document.writeln('<img src=' + pic + '>');
picWindow.document.writeln('</body> </html>');
picWindow.document.close();
}

resizewindow.js
---------------
function resizewindow()
{
// Do resizing here.
// Right now this isn't being executed
alert("resizing window");
}


Can anyone provide some pointers as to why this javascript is failing?
I'm using IE6 on Win2k and when I click on the image to open the popup
window, it does open the window but it is white with no content and the
system immediately goes from about 4% CPU usage to 100% and
consistently stays there until I kill that window with the task
manager.

View 9 Replies View Related

Way To Change Class Name From A Html Page

Sep 1, 2010

So i like to change class name from a html page with javascript.

I found this code that does change the class name

Code:
loopCSSChange = function (el, class, newclass)
{
for (var x=0;x<el.childNodes.length;x++)
{

[Code].....

View 1 Replies View Related

Change Class Name From A Html Page?

Sep 2, 2010

So i like to change class name from a html page with javascript.

I found this code that does change the class name

Code:
loopCSSChange = function (el, class, newclass)
{
for (var x=0;x<el.childNodes.length;x++)
{

[Code]....

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved