Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Can't get element
Message
From
06/03/2013 10:19:09
James Blackburn
Qualty Design Systems, Inc.
Kuna, Idaho, United States
 
 
General information
Forum:
Javascript
Category:
JQuery
Miscellaneous
Thread ID:
01567453
Message ID:
01567612
Views:
33
Hi Viv,

In my version I tried to make content a jquery object in hopes the find would work. It was late and I didn't test my idea (my bad) and it didn't work. This is an interesting idea so I did some more testing this morning and content is a jquery object but find sill won't work. The only way I could get this to work is to append the string to the DOM.
            $("body").append('<h2>SomeText</h2><input id="trapName" value="this is a test."/>')
            console.log($('#trapName').val())
>Aren't the two versions essentially the same ? ie
>v = $(' '); v.find();
>var v = ' ';   $(v).find();
IAC it doesn't work :-{
>
>>content is a string and you are trying to parse a string with jquery. Try this.
>>
>>
var content = $('<h2>SomeText</h2><input id="trapName" />');
>>                var xx = content.find('#trapName');
>>
>>
>>>This is the simplest example I can come up with:
>>
var content = '<h2>SomeText</h2><input id="trapName" />';
>>>                var xx = $(content).find('#trapName');
>>>
>>>
>>>>>It's a standalone fragment - not associated (and cannot be) with the main DOM (which, I believe, is the default context for JQuery).
>>>>>
>>>>
>>>>So, you're saying you tried finding it by its name only and it didn't work, right?
>>>>
>>>>
>>>>>>Why you can not use what Craig posted? Why do you need to access it through the parent?
>>>>>>
>>>>>>Here are few samples from my code:
>>>>>>
>>>>>>
>>>>>>$(document).ready(function () {
>>>>>>    $(":input[data-autocomplete]").each(function () {
>>>>>>        $(this).autocomplete({ source: $(this).attr("data-autocomplete") });
>>>>>>    });  
>>>>>>
>>>>>>    $("form div input").focus(function () {
>>>>>>
>>>>>>        $("form div").each(function () {
>>>>>>            $(this).css("background-color", "white");
>>>>>>        });
>>>>>>
>>>>>>        $(this).parent().css("background-color", "#F2FAED");
>>>>>>        $(this).select();
>>>>>>        $('.SelectOnEntry').focusin(function () {
>>>>>>            $(this).select();
>>>>>>        });
>>>>>>    });
>>>>>>
>>>>>>    $("input:text")
>>>>>>        .focus(function () { $(this).select(); })
>>>>>>        .mouseup(function (e) { e.preventDefault(); });
>>>>>>});
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>>I know how to manipulate it - the problem is that I cannot get a reference to it. Note 'content' in this case is not the default context (the dom document) but a seperate html fragment and $(content).find('#trapName') returns zero results....
>>>>>>>
>>>>>>>>You can address the element directly
>>>>>>>>
>>>>>>>>$("#trapName")
>>>>>>>>
>>>>>>>>If you want to get the value, use
>>>>>>>>var value = $("#trapName).val();
>>>>>>>>
>>>>>>>>To set the value
>>>>>>>>$("#trapName).val("New value");
>>>>>>>>
>>>>>>>>
>>>>>>>>>I think there is something wrong with my understanding of JQuery (which is pretty elemental at best).
>>>>>>>>>
>>>>>>>>>I have a fragment of html. Jquery sees it as this:
$(content): jQuery.fn.jQuery.init[3]
>>>>>>>>>0: h2
>>>>>>>>>1: text
>>>>>>>>>2: input#trapName
>>>>>>>>>length: 3
>>>>>>>>>__proto__: Object[0]
so I thought I could access the input element with
$(content).find('#trapName')
but it finds nothing.
>>>>>>>>>
>>>>>>>>>Any clues. Note this fragment is not in the DOM - but should that matter?
Previous
Reply
Map
View

Click here to load this message in the networking platform