pro78
pro78

Reputation: 75

Change text and add a href to span element Issue

I have a span with an id of randomText and the HTML ofchangingText.

What I would like is the jQuery or plain JavaScript code to change the content when the window is resized.

When the window is less than 480px (this to be both, when the user resizes the browser to less than 480px or when the user uses a mobile device that is less than 480px and do not have to resize the browser) to change the HTML of the span to say I have changed and set an href to the new HTML content that when the user press it to go to www.google.com. If the user is more than 480px to go to the original text without the href.

It is something simple but I would appreciate it if someone could help.

<span id="randomText">changingText</span>

Upvotes: 0

Views: 392

Answers (1)

NotanNimda
NotanNimda

Reputation: 407

I think this should work

$(function(){
$(window).on("resize", function(){
    if($(window).width()<480){
        $("#randomText").html("<a id='changingTextWrapper' href='www.google.com'>I changed!</a>");
    }else{
        $("#randomText").html('changingText');
    }
});
if($(window).width()<480){
        $("#randomText").html("<a id='changingTextWrapper' href='www.google.com'>I changed!</a>");
    }

});

Upvotes: 1

Related Questions