Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I'm using SVG together with jQuery in my Mvc Application. I draw a series of rectangles on my page and what I would like to do is attach a click or mouseover event for each rectangle, for say, popup an alert box.
I've tried something like this, so far:
$("rect[id='Y6']").attr('onclick', function() { alert("Hello!") });
$("rect[id='Y6']").live('click', function() {
alert("Hello!");
But sadly none of this events really worked for this control.
Does anyone know how to do this?
EDIT:
I'm adding the javascript code I'm using below:
<script type="text/javascript">
/*function resetSize(svg, width, height) {
svg.configure({ width: width || $(svg._container).width(),
height: height || $(svg._container).height()
function onLoad(svg, error) {
//svg.text(10, 20, error || 'Loaded into ' + this.id);
//resetSize(svg, null, null); //'100%', '100%');
$(function() {
$('#layout').svg({});
var svg = $('#layout').svg('get');
svg.load('<%= Url.Action("Layout", new{ id = Model.Id }) %>', { //<%= Url.Content("~/media/svg/lion.xml") %>', {
addTo: false,
changeSize: false,
onLoad: onLoad
$('rect#Y6').click( function(){
alert('hello');
</script>
The rectangles are loaded from a svg picture.
–
–
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.