[jQuery] Re: JQuery Selector and Java Script Variable

2008-10-20 Thread Remy Sharp

I just tried dropped in some vanilla XML and it saves and renders
fine:

http://jsbin.com/uwedo/edit

I cleared out the JavaScript tab, and just entered plain old XML in
the HTML tab - the saved output is just XML:

http://jsbin.com/uwedo/



 yeah! I couldn't manage to put xml in jsbin. I followed the ajax video
 without no success.
 Any view where i pasted the xml (JS or HTML views) it was outputted
 without tags. The only manner i found was to paste html encoded
 caracters in the html view. So that the output was fine (at screen)
 ( I do paste that in html view: lt;xmlgt; lt;set
 id=quot;textfieldquot;gt;value for test 1lt;/setgt; lt;/
 xmlgt; )
 Is there a simple way to use xml at jsbin ? like you do with json in
 the ajax video ? Thanx for the jsbin app, it kills all !



[jQuery] Re: JQuery Selector and Java Script Variable

2008-10-20 Thread ricardobeat

You can use this syntax:

if ( $('#elementToBeUpdated').is('input,textarea') ) {
 // use val();
} else {
 // use text();
}

or you can take advantage of the empty return object (only one will
execute):

$('#element').filter('input,textarea').val(new);
$('#element').not('input,textarea').text(new);

or better yet, elements usually don't have a value attribute:

(this.value) ? $(this).val(new) : $(this).text(new);

- ricardo

On Oct 19, 11:30 am, RotinPain [EMAIL PROTECTED] wrote:
 @ Balazs Endresz:
 You're right, and Ricardobeat has given the good answer ;)
 Even if i'm working with Firebug I didn't notice this behavior between
 value and text.

 @Remy:
 yeah! I couldn't manage to put xml in jsbin. I followed the ajax video
 without no success.
 Any view where i pasted the xml (JS or HTML views) it was outputted
 without tags. The only manner i found was to paste html encoded
 caracters in the html view. So that the output was fine (at screen)
 ( I do paste that in html view: lt;xmlgt; lt;set
 id=quot;textfieldquot;gt;value for test 1lt;/setgt; lt;/
 xmlgt; )
 Is there a simple way to use xml at jsbin ? like you do with json in
 the ajax video ? Thanx for the jsbin app, it kills all !

 @ Ricardo:
 val() is working fine in this case, thanx. Nice analysis of the FF
 behavior with textarea text/value attributes ;)

 what i didn't mention is that the element to be updated could be any
 element in the page (textarea, div or p ... )

 The first code I wrote in dev was including a test case for the
 element tagname before to update it, and i was right then! (But when i
 saw that text() was working with textarea too (mainly in IE), i
 deleted this test case using text() for updating any element content).

 Here's the test case I was using :
 var viewer = $([id=' + update[0] + ']);
 var viewertag = viewer.attr(tagName).toLowerCase()
 if (viewertag == textarea || viewertag == input) {
   viewer.val( update[1] );//input detected}

 else {
   viewer.text( update[1] );//other than inputs

 }

 Would there be a method to update any element without any test case ?

 Thank you all for you help. I now understand better why it does not
 always work in FF (IE and SAFARI 3(win32)  where working fine with the
 code) !


[jQuery] Re: JQuery Selector and Java Script Variable

2008-10-20 Thread RotinPain

@ricardobeat:
Great! thank you for your help. I see that there are plenty of manners
that can be used to retrieve the type of an element, now it's to
choose the good one ;) .
I'll use the ternary one for my code but I will also keep in mind the
other functions you gave here for using them in my next coding

@Remy:
I did that already! ... but when i saw that the ouput was without any
tag (stripped), i told myself that the the code won't have been
recognized as xml but as text only. If i understand well, the script
will parse the html tab and not the output tab ?

Again thousand of thanks to all of you here ! you saved me from a
violent headache !!


[jQuery] Re: JQuery Selector and Java Script Variable

2008-10-19 Thread RotinPain

@ Balazs Endresz:
You're right, and Ricardobeat has given the good answer ;)
Even if i'm working with Firebug I didn't notice this behavior between
value and text.

@Remy:
yeah! I couldn't manage to put xml in jsbin. I followed the ajax video
without no success.
Any view where i pasted the xml (JS or HTML views) it was outputted
without tags. The only manner i found was to paste html encoded
caracters in the html view. So that the output was fine (at screen)
( I do paste that in html view: lt;xmlgt; lt;set
id=quot;textfieldquot;gt;value for test 1lt;/setgt; lt;/
xmlgt; )
Is there a simple way to use xml at jsbin ? like you do with json in
the ajax video ? Thanx for the jsbin app, it kills all !

@ Ricardo:
val() is working fine in this case, thanx. Nice analysis of the FF
behavior with textarea text/value attributes ;)

what i didn't mention is that the element to be updated could be any
element in the page (textarea, div or p ... )

The first code I wrote in dev was including a test case for the
element tagname before to update it, and i was right then! (But when i
saw that text() was working with textarea too (mainly in IE), i
deleted this test case using text() for updating any element content).

Here's the test case I was using :
var viewer = $([id=' + update[0] + ']);
var viewertag = viewer.attr(tagName).toLowerCase()
if (viewertag == textarea || viewertag == input) {
  viewer.val( update[1] );//input detected
}
else {
  viewer.text( update[1] );//other than inputs
}

Would there be a method to update any element without any test case ?

Thank you all for you help. I now understand better why it does not
always work in FF (IE and SAFARI 3(win32)  where working fine with the
code) !


[jQuery] Re: JQuery Selector and Java Script Variable

2008-10-18 Thread RotinPain

I met a similar issue, but i can determine it happens only with
Firefox (3.0.3).
The variable selector seems to be the problem.

I explained the whole thing here:http://jsbin.com/aciwi

in short,
$([id=' + variableId + ']).text( variableValue ); won't always
work with FF (it works in first steps)
but
document.getElementById( variableId ).value = variableValue; will
always work

I can't succes in making my code working with jsbin (i tried several
ways to) because the code use ajax with xml and I can't make the
relation between them.

You can view the jquery code here: http://jsbin.com/aciwi
That should load a sample xml here : http://jsbin.com/ebupo
But it does not

Anyway, i posted the same code here at my own ftp:
jquery/html page: http://rotinpain.ifrance.com/tests/test4xml.html
xml data source: http://rotinpain.ifrance.com/tests/test4xml.xml

Let me know if you see something that i didn't. i'm fairly new to
jquery but i think the code is ok.


[jQuery] Re: JQuery Selector and Java Script Variable

2008-10-18 Thread Balazs Endresz

In your case the proplem is that you're using .text() instead
of .value() on the textarea. The strangest thing is why does .text()
even work unless you change the content? It's quite misleading because
it shouldn't work on input elements: http://docs.jquery.com/Attributes/text


On Oct 18, 6:09 pm, RotinPain [EMAIL PROTECTED] wrote:
 I met a similar issue, but i can determine it happens only with
 Firefox (3.0.3).
 The variable selector seems to be the problem.

 I explained the whole thing here:http://jsbin.com/aciwi

 in short,
 $([id=' + variableId + ']).text( variableValue ); won't always
 work with FF (it works in first steps)
 but
 document.getElementById( variableId ).value = variableValue; will
 always work

 I can't succes in making my code working with jsbin (i tried several
 ways to) because the code use ajax with xml and I can't make the
 relation between them.

 You can view the jquery code here:http://jsbin.com/aciwi
 That should load a sample xml here :http://jsbin.com/ebupo
 But it does not

 Anyway, i posted the same code here at my own ftp:
 jquery/html page:http://rotinpain.ifrance.com/tests/test4xml.html
 xml data source:http://rotinpain.ifrance.com/tests/test4xml.xml

 Let me know if you see something that i didn't. i'm fairly new to
 jquery but i think the code is ok.


[jQuery] Re: JQuery Selector and Java Script Variable

2008-10-18 Thread Remy Sharp

Slightly aside to your actual problem - I looked at the jsbin dump you
did and the source XML (http://jsbin.com/ebupo ) and noticed the XML
tags had been escaped - so I've gone in to the database and updated it
manually so your test page now works (or works in that it demonstrates
the problem).

Cheers,

Remy (author of JS Bin...which is why I could edit and fix the source
for you!)



[jQuery] Re: JQuery Selector and Java Script Variable

2008-10-18 Thread ricardobeat


At first, the textarea has 'text content' (inside the tags), and it's
shown inside. When you click the buttons, it updates this text
content.

*But*, when you edit it manually, you are updating the textarea's
VALUE attribute, not the the text inside. When you have both, the
value attribute supersedes the text content. If you inspect the
textarea using Firebug you will see that the text content is still
being changed, it's just not being shown.

Changing the function to use val() instead has it working perfectly.
http://jsbin.com/ozoqi

- ricardo

On Oct 18, 4:10 pm, Balazs Endresz [EMAIL PROTECTED] wrote:
 In your case the proplem is that you're using .text() instead
 of .value() on the textarea. The strangest thing is why does .text()
 even work unless you change the content? It's quite misleading because
 it shouldn't work on input elements:http://docs.jquery.com/Attributes/text

 On Oct 18, 6:09 pm, RotinPain [EMAIL PROTECTED] wrote:

  I met a similar issue, but i can determine it happens only with
  Firefox (3.0.3).
  The variable selector seems to be the problem.

  I explained the whole thing here:http://jsbin.com/aciwi

  in short,
  $([id=' + variableId + ']).text( variableValue ); won't always
  work with FF (it works in first steps)
  but
  document.getElementById( variableId ).value = variableValue; will
  always work

  I can't succes in making my code working with jsbin (i tried several
  ways to) because the code use ajax with xml and I can't make the
  relation between them.

  You can view the jquery code here:http://jsbin.com/aciwi
  That should load a sample xml here :http://jsbin.com/ebupo
  But it does not

  Anyway, i posted the same code here at my own ftp:
  jquery/html page:http://rotinpain.ifrance.com/tests/test4xml.html
  xml data source:http://rotinpain.ifrance.com/tests/test4xml.xml

  Let me know if you see something that i didn't. i'm fairly new to
  jquery but i think the code is ok.


[jQuery] Re: JQuery Selector and Java Script Variable

2008-10-13 Thread Josh Nathanson


That looks like the proper syntax to get your desired selector.  Are you 
getting an error or unexpected results?


-- Josh

- Original Message - 
From: Shadi Almosri [EMAIL PROTECTED]

To: jQuery (English) jquery-en@googlegroups.com
Sent: Monday, October 13, 2008 9:32 AM
Subject: [jQuery] JQuery Selector and Java Script Variable




Hiya,

I've not been able to find an answer to this online! can someone point
out the correct syntax for this:

var myRel = $(this).attr(rel);
var largePath = $('a[rel*=' + myRel +']').attr(href);

Basicly the myRel gets set correctly, but how do i use the javascript
variable as part of the jquery selector so that i can get a selector
that looks like:

(assuming myRel was 5)...

var largePath = $('a[rel*=5]').attr(href);

Thanks in advance!

Shadi