Вопрос

I have a custom tag with format

<ie:menuitems id="ieMenu">Hello World</ie:menuitems>

Now my task is to change the 'Hello World' text, but I am unable to retrieve the value with jQuery/JavaScript, i can get the element for sure because $('#ieMenu").size() gives me 1 as output, but to get the value i tried .text(), .contents(), .val(), .html() but none worked, please help

thanks in advance

EDIT--------------------------------------------------

I think I should mention something here, the above code sample is copied from the page source, i am not sure if this helps you in some way or not, what i wanted to say this is the converted html, and i am running my code in a button click not in page load

Это было полезно?

Решение

Amazing I don't know is it correct or not but I checked and found "Hello World" by using

$("#ieMenu")[0].nextSibling.nodeValue 

and you can assign value as

$("#ieMenu")[0].nextSibling.nodeValue = "Test"

Другие советы

This works for me:

​$(function(){
    var element = document.getElementsByTagName('ie:menuitems')[0];
    console.log(element.innerHTML) 
    element.innerHTML = 'another'    
})​

fiddle: http://jsfiddle.net/WR8MH/

Here is a JSFiddle which does what you want, and works for me in latest Chrome, Firefox, and Opera: http://jsfiddle.net/hTJFk/. The code is reproduced below:

HTML

<html>
    <ie:menuitems id="ieMenu">Hello World</ie:menuitems>
</html>

JavaScript

$(function() {
    $('#ieMenu').text("Goodbye World");
});​

For me, the result was that the tag contained "Goodbye World" as expected.

What browser were you testing on? I suspect that this might be a browser issue, in which case we can try and hack around it.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top