3

How can I append an input value to data-src iframe in jQuery.

var input = $("#input").val();

var iframe = $(".win");
iframe.attr("src", iframe.data("src").join(input)); 
        
console.log(iframe.data("src"));

I am doing like the above snippet but the console.log returns only the initial value without the input value that should be appended.

Does anyone know a way to do it?

1 Answer 1

4

You did not update data-src. You updated src attribute.

var input = $("#input").val();

var iframe = $(".win");
iframe.attr("src", iframe.data("src").join(input)); 
    
console.log(iframe.attr("src"));
console.log(iframe.data("src"));
Sign up to request clarification or add additional context in comments.

4 Comments

isn't that the same as I have?
I mean, you updated iframe `src' attribute. But you did log iframe 'data-src'.
console.log(iframe.data("src")); is your code. But you updated iframe.attr("src", ...
Oh that's right... Got it! I was doing it in the right way but logging the wrong data.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.