[jQuery] Re: outerHTML and Firefox does not work

2007-04-11 Thread Christof Donat

Hi,

> Is there a way to get the equivalent of outerHTML's result of a node
> using jQuery ? (Y/n)

To get something that is similar to outerHTML in Firefox, this might help:
http://developer.mozilla.org/en/docs/XMLSerializer

> $("#test").jquerymagic()

jQuery.fn.jquerymagic = function() {
return this.outerHTML ?
return this.outerHTML :
(new XMLSerializer).serializeToString(this);
}

Christof


[jQuery] Re: outerHTML and Firefox does not work

2007-04-10 Thread Ariel Jakobovits
Could you just say:

function innerHTML(node) {
var id = node.id;
$(this).parent().children().each(function() {
if ($(this).id == id)
return this;
});
}

and then just use what you need from there?

- Original Message 
From: Christian Bach <[EMAIL PROTECTED]>
To: jquery-en@googlegroups.com
Sent: Tuesday, April 10, 2007 6:15:50 AM
Subject: [jQuery] Re: outerHTML and Firefox does not work

You could try this, it's a bit sloppy but what the heck...

$.fn.outerHtml = function() {

$this = $(this);
var h = $this.html();
var s = $this.wrap("").parent().html();

$this.empty().html(h);
return s;
};



   
hello
   
hello2




alert($("#B").outerHtml());


/christian
2007/4/10, Fabien Meghazi <[EMAIL PROTECTED]>:

> Correct. Only Internet Explorer supports "outerHTML". Even "innerHTML"
> started off as a Microsoft only thing, but because it was used so
> widely other browsers have adopted it as a defacto standard.

>
> What are you trying to do that you need to use outerHTML?

Hi everyone in this thead, I was about to ask the same question when I
saw this thread. The problem is that no response has been given, so

let me ask again :

Is there a way to get the equivalent of outerHTML's result of a node
using jQuery ? (Y/n)

Got this:



 





I would like this

$("#test").jquerymagic()

to return this :


 



Same behaviour than $.html() but including the node's tag html too.

It's probably so basic that I must be blind and can't see the
evidence. Please, open my eyes.


Thanks.




-- 
POLYESTER*
Wittstocksgatan 2
115 24 Stockholm
Phone: 08-660 73 50 / +46-8-660 73 50
Mobile: 070-443 91 90 / +46-70-443 91 90
E-mail: 
[EMAIL PROTECTED]
http://www.polyester.se





[jQuery] Re: outerHTML and Firefox does not work

2007-04-10 Thread Christian Bach

You could try this, it's a bit sloppy but what the heck...

$.fn.outerHtml = function() {

   $this = $(this);
   var h = $this.html();
   var s = $this.wrap("").parent().html();
   $this.empty().html(h);
   return s;
   };



  
   hello
  
   hello2



alert($("#B").outerHtml());


/christian
2007/4/10, Fabien Meghazi <[EMAIL PROTECTED]>:



> Correct. Only Internet Explorer supports "outerHTML". Even "innerHTML"
> started off as a Microsoft only thing, but because it was used so
> widely other browsers have adopted it as a defacto standard.
>
> What are you trying to do that you need to use outerHTML?

Hi everyone in this thead, I was about to ask the same question when I
saw this thread. The problem is that no response has been given, so
let me ask again :

Is there a way to get the equivalent of outerHTML's result of a node
using jQuery ? (Y/n)

Got this:



 




I would like this

$("#test").jquerymagic()

to return this :


 


Same behaviour than $.html() but including the node's tag html too.

It's probably so basic that I must be blind and can't see the
evidence. Please, open my eyes.

Thanks.





--
POLYESTER*
Wittstocksgatan 2
115 24 Stockholm
Phone: 08-660 73 50 / +46-8-660 73 50
Mobile: 070-443 91 90 / +46-70-443 91 90
E-mail: [EMAIL PROTECTED]
http://www.polyester.se


[jQuery] Re: outerHTML and Firefox does not work

2007-04-10 Thread Fabien Meghazi



Correct. Only Internet Explorer supports "outerHTML". Even "innerHTML"
started off as a Microsoft only thing, but because it was used so
widely other browsers have adopted it as a defacto standard.

What are you trying to do that you need to use outerHTML?


Hi everyone in this thead, I was about to ask the same question when I
saw this thread. The problem is that no response has been given, so
let me ask again :

Is there a way to get the equivalent of outerHTML's result of a node
using jQuery ? (Y/n)

Got this:


   

   
   


I would like this

$("#test").jquerymagic()

to return this :

   

   

Same behaviour than $.html() but including the node's tag html too.

It's probably so basic that I must be blind and can't see the
evidence. Please, open my eyes.

Thanks.


[jQuery] Re: outerHTML and Firefox does not work

2007-04-10 Thread Karl Rudd


Yes you're both correct. I wrote things out too quickly.

Karl Rudd

On 4/10/07, David Duymelinck <[EMAIL PROTECTED]> wrote:


David Duymelinck schreef:
>
> Klaus Hartl schreef:
>> No, that will throw an error, because at this point: $("#k
>> img").get(i) you already have a reference to the DOM element itself.
>> Thus the following will work:
>>
>> $("#k img").get(i).src
>>
>> or stick to jQuery:
>>
>> $("#k img").attr('src')
>>
> it's it $("#k img").eq(i).attr('src').
>
Too much chocolate affects my english :)

another way to get an attribute is :

$("#k img")[i].src

--
David Duymelinck

[EMAIL PROTECTED]




[jQuery] Re: outerHTML and Firefox does not work

2007-04-10 Thread David Duymelinck


David Duymelinck schreef:


Klaus Hartl schreef:
No, that will throw an error, because at this point: $("#k 
img").get(i) you already have a reference to the DOM element itself. 
Thus the following will work:


$("#k img").get(i).src

or stick to jQuery:

$("#k img").attr('src')


it's it $("#k img").eq(i).attr('src').


Too much chocolate affects my english :)

another way to get an attribute is :

$("#k img")[i].src

--
David Duymelinck

[EMAIL PROTECTED]



[jQuery] Re: outerHTML and Firefox does not work

2007-04-10 Thread David Duymelinck


Klaus Hartl schreef:
No, that will throw an error, because at this point: $("#k 
img").get(i) you already have a reference to the DOM element itself. 
Thus the following will work:


$("#k img").get(i).src

or stick to jQuery:

$("#k img").attr('src')


it's it $("#k img").eq(i).attr('src').

--
David Duymelinck

[EMAIL PROTECTED]



[jQuery] Re: outerHTML and Firefox does not work

2007-04-10 Thread Klaus Hartl


Karl Rudd schrieb:


What do you mean by "required tag"? Do you mean the attributes in the
tag/element, like src="pic1"?

If you want the "src" attribute of the element you have selected you
could do this:

 alert( $("#k img").get(i).attr('src') );


No, that will throw an error, because at this point: $("#k img").get(i) 
you already have a reference to the DOM element itself. Thus the 
following will work:


$("#k img").get(i).src

or stick to jQuery:

$("#k img").attr('src')

But do not mix!


-- Klaus


[jQuery] Re: outerHTML and Firefox does not work

2007-04-09 Thread Karl Rudd


What do you mean by "required tag"? Do you mean the attributes in the
tag/element, like src="pic1"?

If you want the "src" attribute of the element you have selected you
could do this:

 alert( $("#k img").get(i).attr('src') );

Or if you have more than one 'img' inside the '#k' div you could loop
through each like this:

 $("#k img").each( function( index ) {
   // 'index' will be a number from 0 to ( number of 'img's - 1 )
   // 'this' will be set to each 'img' element
   alert( "index = " + index + ", this.src = " + this.src );
 });

Karl Rudd

On 4/10/07, bjb <[EMAIL PROTECTED]> wrote:



thanks a lot
as a jquery beginner I wonder if there is no jquery way to get the required
tag?

best regards

Bernd
--
View this message in context: 
http://www.nabble.com/outerHTML-and-Firefox-does-not-work-tf3549488s15494.html#a9910093
Sent from the JQuery mailing list archive at Nabble.com.




[jQuery] Re: outerHTML and Firefox does not work

2007-04-09 Thread bjb


thanks a lot
as a jquery beginner I wonder if there is no jquery way to get the required
tag?

best regards 

Bernd
-- 
View this message in context: 
http://www.nabble.com/outerHTML-and-Firefox-does-not-work-tf3549488s15494.html#a9910093
Sent from the JQuery mailing list archive at Nabble.com.



[jQuery] Re: outerHTML and Firefox does not work

2007-04-09 Thread Karl Rudd


Correct. Only Internet Explorer supports "outerHTML". Even "innerHTML"
started off as a Microsoft only thing, but because it was used so
widely other browsers have adopted it as a defacto standard.

What are you trying to do that you need to use outerHTML?

Karl Rudd

On 4/10/07, bjb <[EMAIL PROTECTED]> wrote:


Hi,

I've some code that works fine with IE, but not on Firefox (2.0.0.3)
on Vista:

html:



...
...




i=0;
alert($("#k img").get(i).outerHTML );


returns "undefined" in FF
any ideas?




[jQuery] Re: outerHTML and Firefox does not work

2007-04-09 Thread Blair Mitchelmore


outerHTML is an IE only property that only a few other browsers support. 
However, Mozilla's JavaScript implementation rocks so try this code I 
found on :


var _emptyTags = {
  "IMG":   true,
  "BR":true,
  "INPUT": true,
  "META":  true,
  "LINK":  true,
  "PARAM": true,
  "HR":true
};

HTMLElement.prototype.__defineGetter__("outerHTML", function () {
  var attrs = this.attributes;
  var str = "<" + this.tagName;
  for (var i = 0; i < attrs.length; i++)
 str += " " + attrs[i].name + "=\"" + attrs[i].value + "\"";

  if (_emptyTags[this.tagName])
 return str + ">";

  return str + ">" + this.innerHTML + "";
});

HTMLElement.prototype.__defineSetter__("outerHTML", function (sHTML) {
  var r = this.ownerDocument.createRange();
  r.setStartBefore(this);
  var df = r.createContextualFragment(sHTML);
  this.parentNode.replaceChild(df, this);
});

That should allow you to get and set outerHTML like a regular variable.

-blair

bjb wrote:

Hi,

I've some code that works fine with IE, but not on Firefox (2.0.0.3)
on Vista:

html:



...
...




i=0;
alert($("#k img").get(i).outerHTML );


returns "undefined" in FF
any ideas?