javascript - Set HTML <param> element via jQuery? - Stack Overflow

JSJQuery Newb here!I have a value stored in variable, and I need to plug it into a particular <para

JS/JQuery Newb here!

I have a value stored in variable, and I need to plug it into a particular <parameter> element associated with an <object>. Here's an example of what I was hoping I could do:

<script>

    function SetParam(iningValue){
         $('#baz').value = iningValue ;
    }

    $(document).ready (function() {

       // jquery POST happens here, which takes a second or two to plete
       // SUCCESS condition calls SetParam() with a value  

        });
</script>

<object class="foo">
    <param name="bar" value="xyzzy" />
   <param name="baz" value="" id="baz" />
</object>

No joy. The baz parameter controls how the object is visually rendered, and I see no changes to indicate I've successfully changed the value.

I'm not sure if:

A. My syntax is wrong in terms of addressing the "baz" parameter in SetParam()

B. My syntax is fine, but the object has already rendered by the time I hit SetParam(), so setting the value of baz does nothing useful

C. All of the above

Can anyone kick me in the right direction?

(and if my problem includes scenario "B" - is there a way to delay the loading of that <object> until I've actually set the value of the <parameter> that I need to?)

Here's a "JSFiddle" of same - Just found about about this and jsbin. Woot!

/

JS/JQuery Newb here!

I have a value stored in variable, and I need to plug it into a particular <parameter> element associated with an <object>. Here's an example of what I was hoping I could do:

<script>

    function SetParam(iningValue){
         $('#baz').value = iningValue ;
    }

    $(document).ready (function() {

       // jquery POST happens here, which takes a second or two to plete
       // SUCCESS condition calls SetParam() with a value  

        });
</script>

<object class="foo">
    <param name="bar" value="xyzzy" />
   <param name="baz" value="" id="baz" />
</object>

No joy. The baz parameter controls how the object is visually rendered, and I see no changes to indicate I've successfully changed the value.

I'm not sure if:

A. My syntax is wrong in terms of addressing the "baz" parameter in SetParam()

B. My syntax is fine, but the object has already rendered by the time I hit SetParam(), so setting the value of baz does nothing useful

C. All of the above

Can anyone kick me in the right direction?

(and if my problem includes scenario "B" - is there a way to delay the loading of that <object> until I've actually set the value of the <parameter> that I need to?)

Here's a "JSFiddle" of same - Just found about about this and jsbin. Woot!

http://jsfiddle/sPhrw/

Share Improve this question asked May 24, 2012 at 22:24 Russell ChristopherRussell Christopher 1,7073 gold badges21 silver badges36 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

You'll need to either use plain javascript, or jQuery:

$('#baz').val(iningValue);

or

$('#baz')[0].value = iningValue;

or

document.getElementById('baz').value = iningValue; 

or

function SetParam(iningValue){
     var $foo = $('<object class="foo"></object>'),
         $bar = $('<param name="bar" value="xyzzy" />'),
         $baz = $('<param name="baz" value="'+ iningValue +'" id="baz" />');
         $foo.append($bar).append($baz).appendTo(someParent);
}

You will need to swap out the variables and values for those that apply in your situation:

$( document ).ready( function () {
    var obj = $( '<object class="foo"></object>' );
    obj.append( '<param name="bar" value="xyzzy"></param>' );

    $.ajax({
        // other parameters
        success: function (response) {
            obj
                .append( '<param name="baz" value="' + response + '"></param>' )
                .appendTo( 'body' );
        }
    });
});

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745229652a4617620.html

相关推荐

  • javascript - Set HTML &lt;param&gt; element via jQuery? - Stack Overflow

    JSJQuery Newb here!I have a value stored in variable, and I need to plug it into a particular <para

    4小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信