Adding Custom Attributes To HTML?
May 31, 2010
I sometime find it useful to add my own attribute to a HTML tag so that my javascript can access those elements.
For instance, new_attribute in the following anchor tag:
<a href="#" class="someclass" new_attribute="some_value">Click Me</a>
When trying to validate this page, however, it doesn't pass. Some of the below questions likely do not make sense, but I hope you get the idea what I am looking for:Is what I am doing bad practice?Is there another way to allow javascript to specifically select just some elements and not others? Should I instead apply multiple classes to the element, and use some of the classes not to modify appearance, but to allow just them to be selected?If using custom attributes, should they somehow be defined so they pass validation?
View 12 Replies
ADVERTISEMENT
Apr 14, 2010
Here's what I'm trying to do:
1) I get reference to a div that's on my page:
var theDiv = $("#" + divID);
2) Now I want to add a custom attribute tag to it, so for instance I want to add "winWidth" so that the div object now contains "winWidth=" for instance.
3) I want to set winWidth now since it's part of theDiv to a value
I'm not sure how to really do 1 + 2. I need to do this on the fly because some javascript logic later will add these attributes dynamically to the div... outside of what the original div had...I don't care what it had, I know I have it now in a JS variable and now I want to both add some new attributes to the div, and then set them on the fly. I don't need these attributes to be on my page, I just need them added to my div variable reference.
View 3 Replies
View Related
Sep 28, 2007
Let's say i defined my own attribute, called "counter".
<div id="myid" counter="2">test</div>
I know I can read this value trough:
document.getElementById('myid').getAttribute('counter');
But is it possible to add the counter attribute to javascripts known attributes, so I could access it like:
document.getElementById('myid').counter;
View 3 Replies
View Related
Mar 29, 2011
I have some attributes that aren't really standard attributes:
e.g.
<option additional="34">Deep Purple</option>
That "additional" attribute is an attribute that I use with Jquery to add an additional price to the item.How many browsers will work with custom attributes like that? Or will I have to use a standard attribute (Note: if I use Value it overwrites the value inside of the option).
View 1 Replies
View Related
May 1, 2010
how I can get my custom attributes to validate in XHTML Strict? I have to have it validate as it is for a class.Example of the form:
HTML Code:
input onkeyup="TF_filterTable(document.getElementById('dataTable'), filter)" size="40" tf_colkey="name"tf_searchtype="substring" />
Example of the JS:
Code:
var inputs = frm.getElementsByTagName("INPUT");
for (var i=0;i<inputs.length;i++)
{ //looping thru all INPUT elements[code].........
View 2 Replies
View Related
Dec 4, 2010
I'm trying to add a click function to my object. The way i have it now in bold is how I saw someone else use it, it doesn't work. I tried using jquery's bind('click') and this.div.onclick but it runs the function right away upon instantiation.
How can i get this to run only when clicked?
function bubble(id,title,description,year,bubbleIcon,icon,source,length) {//art object from xml
this.id = 'bubble' + id;
this.title = title;
[Code].....
View 3 Replies
View Related
Jul 23, 2009
Enter a search term and:1) Google Blog Results show up2) Twitter Search Results show up3) Google Maps with custom xml data shows upI have accomplished the first 2 parts - http://www.justincener.com/xmlI now want to add in Google Maps. The idea is to type in a athlete's name and have results come back from Google Blog Search (done), Twitter (done), and Google Maps. I only need to show 2-3 choices, so I want to create a custom Google Maps XML doc that corresponds to a few search terms. For example, when someone types in "Tom Brady", I want a Google Map to also come up along with the Google Blog and Twitter Results.
On the map, I want to plot 4 points showing his 4 next games. I think I know how to create the custom XML for GMaps, but I don't know how to implement it so that when someone enters input, the GMaps will show up. Can anyone get me started in the right direction please?Here is the JS so far that handles Google Blog Results and Twitter Results:
var errorCount=0;
var twitter_link;
function searchGoogle(query)
[code]....
View 16 Replies
View Related
Aug 26, 2011
I am developing a mobile web app which communicates with a wcf service that returns data in json format. The way security is handled is the user logins and recieves a token which is added to the http header. The login ajax request which passes the url strings to the service is using https protocol. This works fine. The other 2 ajax requests are also supposed to use https but when I do this the custom header isn't added. If I use http which is the old url, the custom header is added to http header. I have tested this using fiddler2 and firebug and for some reason it doesn't like https in the ajax request url.
function login_service()
{
//$.mobile.pageLoading();
var stringUsername = $('#txtUsername').val();
var stringPassword = $('#txtPassword').val();
[Code]...
View 4 Replies
View Related
Nov 2, 2010
I am working with customised form validator..I've this html structure
<div id="tab-perfil"><fieldset>
<legend>Dados Pessoais</legend>
<div class="columns">
<div class="colx3-left-double required">
<label for="nome">Nome</label>
<span class="relative">
<input type="text" name="nome" id="nome" value="" class="full-width">
</span></div>
What I want to do is after the input add a span, I know how to do that, just use insertAfter('#nome'); but I have a class for the ERROR and a class for the OK. This is what I have so far
this.find("#formulario_criar-cliente").submit(function(){
var $inputs = $('#formulario_criar-cliente div .required :input');
$inputs.each(function() {
if ($(this).val() == "") {
$(this).addClass("error");
} else {
$(this).removeClass("error");
}});
return false;
});
When I add the class error I want to show a span with a class="check-error" and when I remove the class I want to show a span with a class="check-ok" but remove the error one. This is for multiple inputs... and I don't know how to achieve that =x
View 6 Replies
View Related
Jan 26, 2011
Im using the jquery validation plugin: [URL] The forms are generated dynamically using php, with the standard class 'required' the plugin looks for, however when it comes to adding my custom rules i want them to be dynamic, as the name/id attributes are generated based on what the id of the form is: i.e. the form ID is #comp so an input would have a name attribute of comp_forename, comp_surname so basically the validator is initiated by looking in the body for a form: var form_id = $('body form').attr('id'); Then how can icancatante the strings to created the name attributes dynamically in the rules here:
[URL]
View 1 Replies
View Related
Jul 13, 2010
Which is considered best practice?
<div onmouseover="doThis();">
myDiv.onmouseover = doThis;
myDiv.addEventListener("mouseover",doThis,false);
...or something else?
View 3 Replies
View Related
Dec 12, 2009
I'm a neophyte to Javascript, but I need it to dynamically add lines to a form. I was able to cobble together this inelegant looking code below. It adds the row when called, but there are more attributes needed for this to be correct for the application. 1) need to center the input in the TD 2)the input tags need type, size, maxsize, and value attributes added I have not been able to figure out the correct way to do this.
Also, is there a way for the value attribute to work with a PHP echo, or is there a Javascript method to display associative array values?
[Code]...
BTW is there an good online tutorial and/or reference for javascript or book(s) that you could recommend?
View 2 Replies
View Related
Nov 21, 2010
I have this code that when links are clicked the elements are erased. The issue that I am facing is that I want to update the order of the attributes "id" and "var_id". Basically when you remove the first or the second element to update the order. I am not very savvy with DOM so I have hard time developing that functionality. I hope you guys can help me with that.
<html>
<head>
<script>
function removeElement_e(divNum)
{
var d = document.getElementById('e');
[Code]...
View 7 Replies
View Related
Jul 2, 2010
I know that using <a href="javascript:"> and <sometag onclick=""> is evil, but in this particular situation it is quite hard to avoid it due to external powers Anyway here is the issue itself : putting javascript strings inside HTML attributes :
Code:
<button onclick="DoSomething('string')">
Everything is fine until there are single or double quotes INSIDE the 'string' value. Having a double quote inside the string, even JS escaped leads to the onclick argument value being cut :
Code:
<button onclick="DoSomething('str"ing')">
If you replace the double quote by '"' then you don't get a double quote inside DoSomething (you could always replace " by " in JS).
Similar problem if you choose to enclose the onclick argument in single quotes and happen to have a single quote JS escaped inside the string.So, is there any other way of dealing with potential presence of single AND double quotes in the 'string' value, other than replacing them before by ' and " and then replacing them back inside DoSomething ?
View 9 Replies
View Related
Nov 23, 2005
I have a custom HTML tag: <custom>text is here</custom>
I can do anything I would like in terms of calling methods with mozilla
but not IE 6. For instance calling appendChild in IE results in an
error. The innerHTML property is blank even though there is text
between the tag.
Is there a work around for IE. What gives with IE and being able to
access and manipulate custom tags??
View 1 Replies
View Related
Jul 8, 2009
I know very little js, but I've been reading up on it, mainly for one reason. (I'm a PHP programmer and I've just used js for small tasks like client-side form validation, that sort of thing).
What I want to do is make a textarea with buttons, similar to a BB editor, but which will use defined html tags; I'll use <div style="box1"> and <h1 style="greenunderline"> for examples. I've tried to modify some open source editors and get utterly lost in trying, and I'm not sure that approach would work anyway.
The buttons would need to function two ways, again like a BB editor.
1) It could simply insert the start and end tags in the textarea;
2) If text were selected, it would put the tag in front of the selection and the end tag after.
If I can get this done, I think I can handle a preview function. I haven't even gotten close to getting javascript to "get" selected text inside a textarea.
View 1 Replies
View Related
Jun 29, 2011
suppose we have a <a href=www.google.com>google</a> tag in our HTML page.And it is inside a div with class name as chapter. Now i added the script as below,
$(document).ready(
function() {
$(
'div.chapter a').each(function(index) {
[Code].....
View 1 Replies
View Related
Jun 7, 2010
I have a dynamic HTML table which gets populated by coldfusion and displayed, I have a column called performace which holds numeric values. I need to select the top 3 best performace value in the column and then highlight the entire rows in different colours. Can any one help me in doing it?
My server can run only Javascript and coldfusion, No Ajax/PHP.
Hint : Something like a code to highlight a <tr id=#idx#> with this ID = #idx#.
View 2 Replies
View Related
Mar 5, 2011
simple code page with div content, there some things and i do :alert( $("#content").html() ); gives me really nasty code in IE it adds some of default values, changes code to uppercase as for really old html opera and firefox works fine is there a way to avoid custom code added by IE?
View 2 Replies
View Related
Sep 10, 2010
I am trying to find how to use custom tags in html and render data based on their use.
A good example is the joomla <jm:whatever> tag.
I found the following article: [url]
I think it might be outdated though because the behavior:url element does not seem to work. Plus, when I check the style sheet on a joomla site, it doesnt seem to use this method. I think these tags might be xml but I do not know how to render them based on the tag.
For example: <customAbbrv:display src="test.html" label="Test" />
I would want this tag to fire test.html and pass the attribute label which is set to Test.
View 2 Replies
View Related
Jun 17, 2010
I am searching for a jQuery plugin for screenshots gallery, similar to Lightbox, FancyBox, etc. The problem is - I need to display HTML description for each screenshot.
I found a great one that allows layover for any DIV on the page: [URL]
but this one doesn't have a prev-next functionality for multiple divs, as I need to present these in a gallery view.
Do you know any plugin that allows that, or do you have idea how to extend the script to work the way I want?
View 2 Replies
View Related
Jul 10, 2011
I want to store some custom property in HTML element directly, like this:
[Code]...
View 2 Replies
View Related
Jul 23, 2005
I have two problems that I suspect will be bread-and-butter problems for the
more experienced guys on here, but I'm not the greatest with js.
NB: Code snippets at the bottom
The first problem is that after a bit of fiddling I'm getting am 'Object
Expected' error when I click on the Depot dropdown which I can't seem to get
round. The code I had was working OK but then I cut it all out, tidied it
all up, and put it back in and now it doesnt work.
The second problem is a 'How do I...'. I'm using an XML data island to
retrieve some data without submitting the form. In the first example, when
the user selects a Customer, the Depot list is updated with all the depots
for that customer; This all works fine. What I want to do now is retrieve
some more data when the Depot is selected.
I have the XML bits working; the js code snippet correctly output a series
of msgboxes with the correct value in (or at least it did until I introduced
the Object Expect error!).
However, I'm unsure as to how to display this information on the page. The
XML contains a series of Part No's and Quantities, which I'd like to display
in a table towards the bottom of the screen. The problem is that I don't
know how to dynamically create and populate this table.
The only caveat is that I dont want to show the table if no values are
returned from the query....
View 4 Replies
View Related
Aug 10, 2010
I'm trying to find a way to add an attribute inside an anchor. I want to do this is because that attribute is required by a script I have running on the page, but it is not valid.Just so it makes more sense the code looks pretty much like this:<a id="previous" control="-6" href="#"></a> and I would like to add control="-6" inside <a> via jQuery, only I don't know how.
View 1 Replies
View Related
Apr 25, 2009
Ok, the title might not be a very good title, but I'll try to explain a little better INSIDE the post Ok, so here is my example jQuery
$(document).ready(function(){
$('#holder').html('<a href="#" id="foo">Hey!</div>');
$('#foo').click(function(){
[code]....
View 5 Replies
View Related
Aug 29, 2010
I have a table as follows:
<table>
<tr>
<td>col 1</td><td>col2</td>
</tr>
[code]....
You see it doesn't want to output the I have specified. The actual script is a lot more complex and so unfortunately manually adding each using an appendChild or similar function would be far too time consuming and probably rather resource intensive. Is there anyway I can just add a 'chunk of html' to this table row and in this chunk define the table columns?
View 3 Replies
View Related