JQuery :: Cannot Pass A Selector Via A Variable?
May 14, 2009
im trying to figure out how to pass a target selector via a variablethe simple example below dosnt work, i was wondering why when i pass the varible target into the slector it does not work...
var target = "#1 .preview";
$(target).addClass("hidden");
View 1 Replies
ADVERTISEMENT
Aug 5, 2010
I am trying to use (multiple) attribute selector and I have a string variable "txt" that I need to use in the attribute selector to select all <p> with all id's except for the id=txt
$(document).ready(function(){
$("p.par").click(function(){
txt = $(this).attr("id");
[code]....
View 2 Replies
View Related
Mar 27, 2010
I am trying to pass a variable (which is a number) to the :gt(index) pseudo-selector.var thisParentIndex = $(this).parent().index(); //get the index of parent
console.log(thisParentIndex);
$(this).parent().parent().find('div.line:gt(' + thisParentIndex + ')').hide();
this does not appear to work..
View 3 Replies
View Related
Jul 16, 2011
Can I pass the content of an id selector to a variable?I am using a jQuery plugin which passes some data to an id selector ('#alt-text'). If I create a div tag with that id, the content for ('#alt-text') gets displayed in the div tag- everything fine. However, I need to split the selector (or parse the selector) to the assign different sections of the data to differnt div tags.
can't seem to get this started. If I try:
var xxx = $('#alt-text');
$('#otherDivTag').html(xxx);
it does not work. My desire is to do something like:
var xxx = $('#alt-text');
$('#otherDivTag').html(xxx).text().split(' ')[0];
View 3 Replies
View Related
Apr 5, 2010
I am attempting to hack a jQuery extension that does an ajax style form submit. The final result is an image uploader that can run inline. The script is fairly simple - it creates an iframe with a new form, and copies over a form element (the file name), and submits the form. Plus error handling and the like.
The problem is that I need to use from within MVC, and so I need more form values, like the ID of the item I am working on. It would be easy to add another configuration setting for an additional form element to copy over, but I really want to have the ability to pass a jQuery selector in and use that to specify the form elements to copy. Is this possible?
View 3 Replies
View Related
Dec 13, 2011
I want to load an html div in a variable, modify it in another variable; and then change the document injecting the contents.
1. I load the html to be changed in a variable (code)
2. I modify an attribute of <param> using attr() and I put the result in a var (newcode)
3. I change the html in the doc
I've used the debugger, and all steps give the expected results, except of newcode.html(), which is a null string. Why?
[Code]....
View 8 Replies
View Related
Jun 3, 2011
The following code works:
$('#prov_1 .toggleEdit').click(function () {
$('#prov_1 .editable').toggle();
});
When I click on the "toggleEdit" button under #prov_1, the .editable elements in #prov_1 appear/disappear.
Now I want to do this for all prov_N.
$('#prov_' + pid + ' .toggleEdit').click(function () {
$('#prov_' + pid + ' .editable').toggle();
});
does not work. How do I extract or define N, the pid number?
View 4 Replies
View Related
Sep 25, 2010
Is it possible to use a variable in a selector? So instead of this:
$("#slider img").hide();
I want something like this
var wrapper = "#slider";
$(wrapper + " img").hide();
But this is just giving me this error:
uncaught exception: Syntax error, unrecognized expression: [object Object]
View 2 Replies
View Related
Apr 7, 2010
Is it possible for example to do:
var selec = 3
$(selec).etc...
and i wont it to have the same meaning as
$("#3").etc.... ?
View 1 Replies
View Related
Dec 10, 2010
Basically I have a carousel, and when an item is hovered on, it's corresponding titles needs to show up below. I've managed to get a very inefficient version this working by repeating the function with the explicit id for the list item, but I'd like to get this working in a more automated fashion by assigning a variable that can be used with both the list item id and the paragraph id. I'm not sure if index() is the best way to go about this, or how to actually add the variable to the id's.
The HTML --
<div id="carousel_holder">
<ul id="carousel">
[code]....
View 1 Replies
View Related
May 26, 2010
I am new to Jquery.Is it possible to use variables instead of selectors? For exampleinsteadof #list2, #list3at the code below is it possible?
$(function(){
$("select").change(function() {
var selectedAttr = this.getAttribute("id")
[code]....
View 2 Replies
View Related
Oct 22, 2011
I'm am trying to make a script that looks something like this:[code]This of course doesn't work. I don't no how to put the javascript variable v1 into the id selector to target the DIV with id="v1".I'm more a designer then a programmer.
View 5 Replies
View Related
Oct 30, 2009
thisState="ALHouse";
I want to select all elements of class="placemark" and whose parent is thisState.
View 1 Replies
View Related
Dec 3, 2010
function findDivs(id)
{
$('div[id~="' + id + ''"]').innerHTML = "insert this text into div's with id that contains the variable: id";
}
So the selector i am using isn't working. I'm pretty new to jQuery so the selector may be completely off.
View 1 Replies
View Related
Mar 11, 2010
I have a number of input fields and pass their name and ID to this function, in order to clear the defaults and remove the initial class. :
[Code]...
View 2 Replies
View Related
Sep 14, 2011
I have a table where I hide a table row when the listen "item" is deleted. The item is deleted via jquery ajax. When the delete button is pressed, I call a plugin that creates a confirmation box. The plugin is passed a function to perform if 'Yes' is pressed.
[Code]...
The $(hideThis).hide(); line works. The tr is hidden from view. The next line is where I'm stuck. I know that how it is currently set up would never work, but looking at this will help you understand what I need to do. I want to edit the classes of all the tr tags that follow the one I just hid.
Here's the issue. I cannot just call the tr tag the same way I did to set the variable since I am no longer working in the same scope. And if I were to use this script the way it is written, the element it is looking for for the each statement is "[object] [object] ~ .lineItem".
View 5 Replies
View Related
May 20, 2010
How can I dynamically specify a class value to use in a selector? For instance, I have a number, and I need to identify an element that ends with that number. In this case, there are four divs that have class values of
my_id_0
my_id_1
my_id_2
my_id_3
I have a 0 (obtained previously in the code) stored in the value tabId, so I want to get the values of the class attribute for <div id="my_id_0">. How do I create my selector? I tried
$("div# parent_element_id #my_id_" + tabId).attr("class");
but it comes back as undefined. Do I need to define it as a variable and put it in theelector that way? Or is there another way?
View 1 Replies
View Related
Jun 3, 2011
I'm trying to define a selector as a global variable and it keeps coming back undefined. I tried creating a namespace for it but had no luck. I would like to be able to reference the sliderRange, currentMin, currentMax globally.
SLIDER.range = $('#price-slider').slider('option','values');
SLIDER.min = SLIDER.range[0];
SLIDER.max = SLIDER.range[1];
[code]....
View 1 Replies
View Related
Dec 17, 2010
I am new to jQuery. How can I select all the elements with a given number and which has 0 has value and set to a specified value.
[Code]...
View 3 Replies
View Related
Feb 16, 2010
Why this works
$("#test a:first[rel*='modal']").css("background-color", "red")
And this does not!!!
var testing='modal';
$("#test a:first[rel*=testing]").css("background-color", "red");
View 1 Replies
View Related
Apr 16, 2010
I'm trying to use a variable as part of a selector. When I insert the variable into the selector it doesn't work. But if I hardcode the variable into the selector it works fine. Here's an example:
[Code]...
View 1 Replies
View Related
Dec 15, 2009
Here's what I hope to be a quick question that I should be able to figure out myself... but, unfortunately, I can't...I'm trying to pass a variable into the attribute selector. When I substitute the "+myHref+" for "http", I get a match. When I log the myHref var, I get a match. What's wrong with my syntax? Why isn't the myLink finding a match?
[Code]...
View 3 Replies
View Related
Oct 5, 2010
I try to load specific text from a page into a string. When I'm on the specific page I can do this as follows: var wantedText = $("td > span[style='color: #00AA00; font-weight: bold;']").text();But I want to get this text from another webpage using AJAX, I tried using .load() as follows:
$('#somediv').load(Url+" td > span"); //this loads 3 spans into #somediv (including the one I need)
$('#somediv').load(Url+" td > span[style='color: #00AA00; font-weight: bold;']"); //this does nothing
I also tried loading the entire page into a string using .ajax() like this:
[Code]....
View 3 Replies
View Related
Apr 15, 2011
What is the syntax for accessing the children of a class, where the class is a variable?The html structure is multiple divs like this:
<div class="class1 class2 class3">
<p class="x"> lorem</p>
<p class="y"> ipsum</p>
<p class="z"> yadda</p>
</div>
(There's a structural reason for accessing the child <p> tags, rather than just the parent <div>s. Some <p> tags in some<div>swill have previously had a style change applied: if the changes are now applied only to the parents, some children won't changeā¦ at least not till they're hidden).Anyway: this code doesn't work, doesn't generate a FF error message, and doesn't stop subsequent chained functions from operating. So it can't be far off; and the syntax$(cl + ' > p') works ok in another function.
View 6 Replies
View Related
May 21, 2010
I have the following that works just fine. If the div ID includes the string "targetDiv" then alert.
[Code]....
View 2 Replies
View Related
Jul 13, 2011
I'm passing a variable to a selector. I have found a few resources and tried to implement them but they're just not working for me. I am trying to find href that match my variable and am working with the following:
var itemLink = /site/Mario-Kart..etc.
$("a[href=" + itemLink + "]").......etc.
I receive an error "Uncaught Syntax Error unrecognized expression: [href=/site/Mario-Kart..etc. ]" I have been placing the quotes in different places to correct the syntax but to no avail. Also, this works with JQuery v1.44 and earlier but not after.
View 4 Replies
View Related