?
Solved

How do I insert a piece of html code inside an html tag using jquery?

Posted on 2014-07-19
5
Medium Priority
?
283 Views
Last Modified: 2014-07-22
Hi,

I have a line of HTML code as follows:
<a href="test.html" title="home">CLICK</a>

Open in new window


I would like to insert the following code before ">CLICK":
data-tip="Pause Video" href="javascript:void(0);" onclick="pauseBgVideo();"

Open in new window


so that the result is like this:
<a href="test.html" title="home" data-tip="Pause Video" href="javascript:void(0);" onclick="pauseBgVideo();">CLICK</a>

Open in new window



I am using jQuery. How do I achieve this?

thanks in advance
0
Comment
Question by:badwolfff
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 53

Accepted Solution

by:
Scott Fell,  EE MVE earned 2000 total points
ID: 40206144
$(function(){
$('#test').attr('data-tip','Pause Video').attr('href','javascript:void(0);').attr('onclick','pauseBgVideo();');
});

Open in new window


<a id="test" href="test.html" title="home">CLICK</a>

Open in new window

0
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 40206174
Your 'result' has two 'href's and that's an error.
0
 
LVL 53

Expert Comment

by:Scott Fell, EE MVE
ID: 40206211
Dave, the jquery attr command over writes and does not add.   Are you seeing something different?

link
0
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 40206513
I was talking about the original post.
0
 

Author Comment

by:badwolfff
ID: 40211708
I've tried the code and it doesn't work.
I've left it on the site for the moment.
I am trying to see if I can find a workaround too.

thanks
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Find out what you should include to make the best professional email signature for your organization.
This article discusses how to implement server side field validation and display customized error messages to the client.
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question