0

I am having trouble changing my <embed> src attribute.

(JQuery)

for (index in Forcast) {
var imageurl = "http://localhost/DesktopVersion/Inc/Images/Weather/";
var imagename = Forcast[0]['icon']+".svg)";
var WeatherIcon = imageurl+imagename;
var parent = $('embed#GetWeatherIcon').parent();
var newImage = "<embed scr=" + WeatherIcon + " />";
var newElement = $(newImage);

$('embed#GetWeatherIcon').remove();
parent.append(newElement);
....

(HTML)

<div>
<embed id="GetWeatherIcon" type="image/svg+xml" />
</div>

(CSS)

#GetWeatherIcon {
height:150px; width:150px; margin:30px 0 0 35px; padding:0; border:0; position:absolute;
}

If someone could please point out what i need to change that would be great. Thanks a bunch!

ChristopherStrydom
  • 7,338
  • 5
  • 21
  • 34

2 Answers2

3

newElement variable is missing there.

You should change

var newImage = "<embed scr="Image" />";

to

var newImage = "<embed scr=" + Image + " />";
var newElement = $(newImage);

and then should work

$('embed#GetWeatherIcon').remove();
parent.append(newElement);

Changing of src attribute is not working by this question

$('embed#GetWeatherIcon').attr('src', Image); // NOT WORKING

UPDATE:

I try your latest code and I find a problem. You made a mistake in src attribute name, you wrote scr and than it could not work. You also have an mistake in var imagename = Forcast[0]['icon']+".svg)";, there is probably wrong closing bracket.

Here is my working code:

<!DOCTYPE HTML>
<html>
<head>
  <meta http-equiv="content-type" content="text/html; charset=UTF8">
  <meta name="generator" content="HTML hackers, wwww.htmlhackers.com">
  <title>Embed object change</title>
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
  <style>
    #GetWeatherIcon { 
      height:150px; width:150px; margin:30px 0 0 35px; padding:0; border:0; position:absolute;
    }
  </style>
</head>
<body>
  <script>
    $(document).ready(function() {
      $('#change_btn').click(function() {
        var imageurl = "http://upload.wikimedia.org/wikipedia/commons/e/e8/";
        var imagename = "Svg_example3.svg";
        var WeatherIcon = imageurl+imagename;
        var parent = $('embed#GetWeatherIcon').parent();
        var newImage = "<embed id=\"GetWeatherIcon\" src=\"" + WeatherIcon + "\" type=\"image/svg+xml\"/>";
        var newElement = $(newImage);

        $('embed#GetWeatherIcon').remove();
        parent.append(newElement);
      });
    });
  </script>
  <p id="change_btn">Change</p>
  <div>
    <embed id="GetWeatherIcon" src="http://upload.wikimedia.org/wikipedia/commons/c/c9/Svg_example4.svg" type="image/svg+xml" />
  </div>
</body>
</html>
Community
  • 1
  • 1
Boris Šuška
  • 1,796
  • 20
  • 32
  • thank you for the answer :) But neither way seemed to work? The image still doesn't show up :/ – ChristopherStrydom Mar 09 '13 at 13:13
  • i have updated the question to show my new code which is what you suggested. I don't know if i have done anything wrong but its not working. Could you please check it? – ChristopherStrydom Mar 10 '13 at 18:51
  • Thanks a lot for the update and sorry for the late reply. I have changed everything but i don't know what you mean when you say "...mistake in `var imagename = Forcast[0]['icon']+".svg)";`, there is probably wrong closing bracket". You did not add this in your code so i could not workout what i have done wrong... – ChristopherStrydom Mar 15 '13 at 20:23
  • What is evaluation of `Forcast[0]['icon']+".svg)"`? I gues that it is something like `"http://www.somepage.com/img/icons/forecast.svg)"` then bracket at end of string is wrong, because when you type this into browser you get 404 - Page not found error. Then try `"http://www.somepage.com/img/icons/forecast.svg"` and this may work. – Boris Šuška Mar 20 '13 at 18:13
  • Oh man I'm sorry for wasting your time :/ for some reason i thought i needed the bracket to close/encapsulate the call/command what ever it is. I then looked at it now and realized that i didn't even have an opening bracket to go with it :/ I'm such a Muppet. Thank you so much for your patience and help, its all working now! – ChristopherStrydom Mar 20 '13 at 19:10
0

I am not sure,bt remove src from html and give other name in source path :

var newImage = "<embed scr="new source" />";
Amrendra
  • 2,019
  • 2
  • 18
  • 36